Question

I am trying to create a script that gets all the servers' patch installations in our environment. The script I am running is giving me continuous output without printing any success messages after each server read from text file. I have written a fairly basic script! Doh.

I want to insert some code into my script which, either prints each server details with a Break / Success message before printing another server continuously in CLI, or prints each server in a separate text file. Please find the below Code:

$Computers = gc ServerListFile.txt

Get-hotfix -computer $Computers

Please give me some input at least, to try and get it done.

Was it helpful?

Solution

It looks like it is accepting the $Computers variable as a string instead of a string[] (array).

You need to put it through a loop to specify a newline after each set of hotfixes:

$computers = gc ServerListFile.txt
ForEach ($computer in $computers) {

    # You could even put the computer name at the beginning of the hotfixes
    "Hotfixes for $($computer)" | Out-File hotfixes.log -a -en ASCII

    # Get the hotfixes and output to text file
    Get-Hotfix -computer $computer | Out-File hotfixes.log -a -en ASCII

    # Add a new line after each computer's hotfixes
    "`n" | Out-File hotfixes.log -a -en ASCII
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top