Categories

Logging non-contactable systems

In this post - http://msmvps.com/blogs/richardsiddaway/archive/2011/10/23/1760058.aspx – I showed how to get the date of the last update applied to a system.  A comment was posted asking how to log machines that can’t be contacted

".", "rslaptop01", "200.0.0.1" | foreach {              
    if (Test-Path -Path hotfix.log){Remove-Item -Path hotfix.log -Force}            
                
    if(-not(Test-Connection -ComputerName $_ -Count 1 -Quiet)){            
      Add-content -Path hotfix.log -Value "Could not contact $($_) at $(get-date)" -Encoding ASCII            
    }            
    else {            
      Get-HotFix -ComputerName $_  |              
      Where {$_.InstalledOn} |              
      sort InstalledOn -Descending |              
      select CSname, @{Name="Installed";              
      Expression={"{0:dd MMMM yyyy}" -f [datetime]$_.InstalledOn.Tostring()}} -First 1             
    }            
}


Simply add a couple of lines to run Test-Connection and if you don’t get an answer then write out to a log file.

One Response to Logging non-contactable systems

  • Branko says:

    this code below working for me but im not good enough with PS to make logging working :)
    i have a list with servers scan the for last update and export to csv. so if you could help me add this i would be very greatful :) tnx in advance.

    Branko

    $content = @();
    Get-Content “C:\servers.txt” |foreach {
    $content +=
    Get-HotFix -ComputerName $_ |
    Where {$_.InstalledOn} |
    sort InstalledOn -Descending |
    select CSname, @{Name=”Installed”;
    Expression={“{0:dd MMMM yyyy}” -f [datetime]$_.InstalledOn.Tostring()}} -First 1
    }
    $content | Export-Csv C:\update.csv

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>