Automation

 View Only
  • 1.  How to send a new output of the script to a new file?

    Posted Feb 02, 2016 02:13 PM

    Hi guys,

    Im the powercli world and i need some help.

    I create an script for collect the active alarm on vcenter, the script work fine .

    Now i need to send the result to a txt, i use :

    $date = get-date -uFormat "%d%m%y"

    $alarms | out-file C:\PS-Scripts\ReporteAlarmasvcenterXX-$date.txt

    So, the script then the outputo to the txt file but when i execute again the script the output is send it to the same file,

    How can a send the output to a new file?  :-.( .,

    I found that with the command get-date -format D i get the the date in the name of the file but when a tried .-format G "date + hour" i receive an error from the scrit , that the path is not found.

    I need to change the path?

    Thanks

    Carlos



  • 2.  RE: How to send a new output of the script to a new file?

    Posted Feb 02, 2016 02:53 PM

    Maybe this can help you. I used it every time I need. Change what you need. This part of script make a directory (if not exists) with date of the day

    # Define the backup target path (this path will be created if it doesn't exist)

    $ParentBackupLocation = "C:\Reports\"

    $ResourceFileLocation = $ParentBackupLocation + "Resources\"

    $BackupLocation = $ResourceFileLocation  + "{0:yyyy-MM-dd-tt}" -f (Get-Date)

    $BackupLocationtest = Test-Path -path $BackupLocation

    If ($BackupLocationtest -eq $false) {mkdir $BackupLocation | Out-Null}

    Then you can put date into filename :

    $Dateformat = get-date -f MMddyyyy

    $filelocation=$BackupLocation + "\VCloud_Report_" + $Dateformat + ".txt"



  • 3.  RE: How to send a new output of the script to a new file?

    Posted Feb 02, 2016 05:43 PM

    Hi ,

    Thanks for your quickly reply. One question, "Resources is the new file that is move to the sub-folder Parent backup localtion?

    Best regards

    Carlos



  • 4.  RE: How to send a new output of the script to a new file?

    Posted Feb 03, 2016 04:09 PM

    Hi,

    Finally i follow your step but when i run the script i dont see the new file in the backuplocation

    $alarms | out-file C:\Reports\VCloud_Report-$Dateformat.txt >>>>>>>>>>>><< Original file or first file generate during the day.

    $ParentBackupLocation = "C:\Reports\"

    $ResourceFileLocation = $ParentBackupLocation + "Resources\"

    $BackupLocation = $ResourceFileLocation  + "{0:yyyy-MM-dd-tt}" -f (Get-Date)

    $BackupLocationtest = Test-Path -path $BackupLocation

    If ($BackupLocationtest -eq $false) {mkdir $BackupLocation | Out-Null}

    Then you can put date into filename :

    $Dateformat = get-date -f MMddyyyy

    $filelocation=$BackupLocation + "\VCloud_Report_" + $Dateformat + ".txt"

    This is due to the  >>>>>>>>>< $alarms | out-file C:\Reports\VCloud_Report-$Dateformat.txt

    thanks!



  • 5.  RE: How to send a new output of the script to a new file?

    Posted Feb 11, 2016 10:36 AM

    With my script, you should have created those directory before ("Report" and "Resources"). Otherwise, it will not found the full path

    Regards



  • 6.  RE: How to send a new output of the script to a new file?

    Posted Feb 11, 2016 02:22 PM

    @icrow1978 Simply use "Add-content". This will add the content to the new line. simple but effective.