Append results of a variable to text

Welcome Forums General PowerShell Q&A Append results of a variable to text

This topic contains 1 reply, has 2 voices, and was last updated by

 
Moderator
1 year, 10 months ago.

  • Author
    Posts
  • #63012

    Participant
    Points: 0
    Rank: Member

    Hi folks,

    I'm sure this is an easy thing to sort out..

    So here is a sample of my code:

    #Query the dashboard on netapp filer and return result
    $gather_dashboard =
    {
    write-host "* Alarm Dashboard *"
    (Get-NcDashboardAlarm | format-table -AutoSize)
    }
    "`n"

    #run the gather variables and output to output.txt
    $today = Get-Date
    $dir = "$data_dir_date\output.txt"
    Add-content $dir "Netapp health Checks for $filer1, $today"
    *****here i want to write the output of $gather_dashboard into the text file $dir, then create a new line in text file and do the same thing with a different variable*****

    SO what i am trying to achieve is a log of the ouput of each variable of which there are 6 or 7. There would have to be 3 lines between each output, and each output has a relevant title inserted.

    Currently anything i do overwrites the text file with each variable or just produces nothing.

    What do I need to do?

  • #63016

    Moderator
    Points: 24
    Team Member
    Rank: Member

    Please try below:

    $today = Get-Date
    $dir = "$data_dir_date\output.txt"
    "Netapp health Checks for $filer1, $today" | Out-File -FilePath $dir -Append
    

The topic ‘Append results of a variable to text’ is closed to new replies.