Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Help needed in modifying script to get latest windows update on certain servers ?

$
0
0

People,

I've come up with this script below to perform:

  1. Grab the content of text file for list of server name
  2. Test / check if the server is online, if it is not, then write the error in $ErrorLog = "C:\TEMP\retry.txt"
  3. For all online server grab the  HotfixID, Computername, InstalledOn, InstalledBy, OSVersionattributes
  4. Export to CSV file as the result.

Here's the script that I can come up so far with the way to call the function:

function Get-PatchLevel1 {

param (

[string[]]$serverlist,

[string]$ErrorLog = "C:\TEMP\retry.txt",

[switch]$LogErrors

)

$serverlist |

ForEach-Object {

$server = $_

If (Test-Connection -quiet -computername $server) {

$ADC = Get-ADComputer $server –Property OperatingSystem

Get-HotFix -ComputerName $server |

ForEach-Object{

New-Object PSObject -Property @{

Computername = $server

OSVersion = $ADC.OperatingSystem

Hotfix = $_.HotfixID

InstalledOn = $_.InstalledOn

InstalledBy = $_.installedby

}

}

}

}

}

 

And this is how I call the function:

Get-PatchLevel1 -serverlist "PRODAPPS01-VM", "PRODSQL06-VM", "PRODDC02-VM", "PRODNAS05-VM"  |
	Export-Csv C:\TEMP\PatchLevelAdServers1.csv -NoTypeInformation

However, there are some issues here:

1. The offline server is not written to the $ErrorLog = "C:\TEMP\retry.txt"
2. I just need the latest update entry displayed as in Control Panel\System and Security\Windows Update\View update history in the result in C:\TEMP\PatchLevelADServers1.csv one server per line, is that possible ?

Any kind of help would be greatly appreciated.

Thanks, 


Viewing all articles
Browse latest Browse all 6937

Trending Articles