Skip to content

Instantly share code, notes, and snippets.

Last active January 19, 2016 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e93f472456fcb83b57c4 to your computer and use it in GitHub Desktop.
Save anonymous/e93f472456fcb83b57c4 to your computer and use it in GitHub Desktop.
Function Get-PatchDetails {
[cmdletbinding()]
Param( [parameter(Mandatory)]
[String]$HotFixID,
[parameter(Mandatory,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[String[]]$ComputerName
)
Begin {}
Process {
#Iterating through each Computer in Computername
Foreach ($Computer in $ComputerName ) {
#Checking if the Computer is Online
IF (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
$Status = 'Online'
#Using Try function to catch any error
Try { $ID = Get-HotFix -Id $HotFixID -ComputerName $Computer
$Hotfix = $ID.HotFixID
$Description = $ID.Description
$Hotfix = $ID.HotFixID
} #Try
#If any error occurred
Catch {
$HotFix = 'Not Installed'
} #Catch
} #If
#If Computer is Offline - execute script inside Else function
Else { $Status = 'Offline'
$Description =''
$Hotfix = ''
} #Else
#Creating Custom Object
$Prop = [ordered] @{ 'Server' = $Computer
'Description'= $Description
'HotfixID' = $Hotfix
'Status' = $Status }
$Object = New-Object PSObject -Property $Prop
Write-Output $Object
} #Foreach
} #Process
} #Function
#Examples
#Get-PatchDetails -HotFixID KB3133431 -ComputerName Localhost
#Get-PatchDetails -HotFixID KB3133431 -ComputerName Server01,Server02,Server03
#Get-PatchDetails -HotFixID KB3133431 -ComputerName (Get-Content C:\Test\Computerlist.txt)
#Import-Csv C:\Test\Computerlist.csv | Get-PatchDetails -HotFixID KB3133431
#Get-PatchDetails -HotFixID KB3133431 -ComputerName Server01,Server02 | Export-Csv C:\Test\Report.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment