Patch Details

Tagged: ,

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Vincent Karunaidas Vincent Karunaidas 8 months, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34007
    Profile photo of Partho Sankar Roy
    Partho Sankar Roy
    Participant

    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)}

    }
    }

    #34023
    Profile photo of ertuu85
    ertuu85
    Participant

    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"
    	}
    }
    
    #34035
    Profile photo of Vincent Karunaidas
    Vincent Karunaidas
    Participant

    Get-PatchDetails Function

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.