Run Script on Multiple Servers

Hey all,

I’m trying to figure out how to run a script that goes out and only downloads all available windows updates. This makes patching from Windows Update go much quicker as you only have to install and reboot. Right now all of this is handled manually. We are looking at automating our patching procedures, but that is a topic for another time. Here is the script I have so far:

$Servers = get-content “c:\temp\servers.txt”
foreach($Server in $Servers)
{
$computer = $env:computername

$body = Get-WUInstall -DownloadOnly -AcceptAll -UpdateType Software -Verbose | out-string;

$recipients = “<david.solnok@mycompany.com>”
write-host ($body)

$email = @{
From = “WindowsUpdates@mycompany.com
To = $recipients
Subject = “Downloaded Updates on $computer”
SMTPServer = “insert IP address”
Body = $body
}
send-mailmessage @email
}

Right now it appears that it is only running the script on the server that I’m logged into via RDP. I also tried this script using the invoke-command commandlet but couldn’t get that to work either.

Any assistance is greatly appreciated, thanks!

Not sure what the scripts are really getting you as you can use WSUS and GPO to setup automatic download\installation for free.

As far as the script, you are correct, it is only working on the local computer as you are not passing a computer in the parameters. This function, which I assume is this PSGallery Function for Get-WUInstall uses an old COM object, so it’s limited. Attempt to use Invoke-Command to execute the code on the remote system, just keep in mind that you need to have the function in the code block you send to the remote system. Also if you look at the free resource, there is an eBook on Remoting if you are new to that. Most WSUS settings are just registry entries, so it’s much easier to change the settings via GPO to have the client report to the centralized WSUS instance and manage WSUS clients rather than touching endpoints with scripts.