Get Install Date & OS Version for a list of Servers provided in a text file

Get Install Date and OS Version for a list of Servers provided in a Text file and publish the result in CSV.
Script reads each and every IP/hostname from the inputfile “Serverlist.txt” (Create a Text File “Serverlist.txt” in the same path you save this script), checks if the IP/hostname can be reached. if it can be reached connects to WMI and collects the Install Date and OS Version (Caption) and we dump it in a CSV file in the same path where you have this script.
<# 
Author : Preenesh Nayanasudhan 
Script : Get Install Date and OS Version for list of Servers provided in Text file Serverlist.txt
Purpose : Get Install Date and OS Version for list of Servers provided in Text file and publish the result in CSV 
Pre-requisite : Create a Text File Serverlist.txt in the same path you save this script 
#>  
  
# Input File 
$Servers = Get-Content "ServerList.txt"  
$report = @() 
 
ForEach ($server in $Servers)  
{  
    #Test if computer is online      
    if (test-Connection -ComputerName $server -Count 3 -Quiet )  
    {  
        $PingResult = 'Server IS Pinging'         
        # Connect to WMI on remote machine to get the required information 
        $gwmios = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $server  
        # Get the Install Date and Convert readable date & time format  
        $osidate = $gwmios.ConvertToDateTime($gwmios.InstallDate) 
        $osname = $gwmios.Caption 
        $tempreport = New-Object PSObject  
        $tempreport | Add-Member NoteProperty 'Server Name' $server 
        $tempreport | Add-Member NoteProperty 'Ping Result' $PingResult 
        $tempreport | Add-Member NoteProperty 'OS Version' $osname  
        $tempreport | Add-Member NoteProperty 'OS Install Date' $osidate 
        $report += $tempreport  
    }   
    else   
        {   
        $PingResult = 'Server NOT Pinging'  
        $tempreport = New-Object PSObject  
        $tempreport | Add-Member NoteProperty 'Server Name' $server 
        $tempreport | Add-Member NoteProperty 'Ping Result' $PingResult 
        $report += $tempreport  
    }    
}  
$report | Export-Csv -NoTypeInformation ('OSInstallDate.csv')

!! Preenesh

Advertisements
This entry was posted in Powershell and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s