-
-
Save anonymous/e93f472456fcb83b57c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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