Patch Details

Hi Guys,

I am trying to create a function which will check for a specific KB on a list of servers and generate the report, I am all done so far, however can someone help me on a validation for checking the servers status, What I am looking for is if the server is online then only the script would run else the it will write an error in the report file. I have tried using test-connection but dunno about array and collection as I am not from a developing back ground.

Below is what I have wrote so far.

function Get-PatchDetails

{

[CmdletBinding()]

Param (

$path,
$id,
$reportfile)

$Computers=Get-Content -Path $path

foreach ($c in $Computers)

{

if (Get-HotFix -Id $id -ComputerName $c )

{Add-Content “$c have the patch $id” -Path $reportfile}

else

{(Add-Content “$c doesnt have the patch $id” -Path $reportfile)}

}
}

Hey, you can use something like this…kind of a skeleton one I use for testing connection/bad access/cant ping’s.

You’ll have to add whatever report building you’d like in each section

$svrlist = get-content serverlist.txt

foreach ($svr in $svrlist) {

	if ((test-connection -computername $svr -count 1).StatusCode -eq 0) {
		try
		{
			#works if in here       
        	}
        
       		catch 
		{
        		#Can't Access"
       		 	continue
       		}
	}
	else 
	{
		#Can't Ping"
	}
}

Get-PatchDetails Function
https://gist.github.com/anonymous/e93f472456fcb83b57c4