Get list of Server OS versions and last reboot date

Hi, I have a bunch of servers that i’d like to run a small script weekly to check they are all being rebooted for windows patches regularly I would also like to list the OS versions too as with older servers on windows 2008 they do not require a reboot and I can quickly identify them and ignore. Essentially i’d like 3 columns

  1. Server name
  2. Last Reboot Date
  3. OS Version

I have tried to work this out myself, found lots of examples of how to get this info such as Get-ComputerInfo but not get anywhere near to creating anything. I got to one point where I had an output to a gridview with the server names & last reboot details but the OS version column kept coming back empty.

OK. So what’s the question? Where is your code?

And - just to mention it at least once - the support for Windows Server 2008 has ended. If you’re still running servers with this version of Windows Server you should urgently update them to a supported version.

Hi Olaf and thanks for your response, we have a project at moment to decommission all our old servers but it’s taking some time.

Here is the script I currently have

$ComputerName = ‘servername’
Get-CimInstance -ClassName CIM_OperatingSystem -ComputerName $ComputerName |
Select-Object -Property PSComputerName,LastBootupTime,OperatingSystemVersion
#Sort-Object -Property LastBootupTime

I have tried ‘WindowsProductName’, ‘OperatingSystemVersion’, ‘OSName’ and they all come up blank but I know those fields have contents from running Get-ComputerInfo

Hi Olaf,

I have just had a breakthrough found another example which works locally.

Get-CimInstance Win32_OperatingSystem | Select-Object Caption, LastBootupTime, CSName | out-gridview

However, can you please help me to set this up so I can run it against, I would like to refer to the text files in this these locations and output to email rather than gridview

“\srht-backserv\scm\development\Application Support\SCM\Scripts\WeeklyChecks\SERVER_REBOOT_CHECK_Email\SCM_Machine_List.txt,\srht-backserv\scm\development\Application Support\SCM\Scripts\WeeklyChecks\SERVER_REBOOT_CHECK_Email\dbMotion_Machine_List.txt,\srht-backserv\scm\development\Application Support\SCM\Scripts\WeeklyChecks\SERVER_REBOOT_CHECK_Email\App_Support_Machine_List.txt”

Sorry, I did not get that. I’d recommend to safe the output of the command to a variable in the first place. So you’re able to use it later on again and again if needed.

If you want to send the output to a file you use Out-File or Set-Content. If you want to send a mail message you use Send-MailMessage and insert it as body or attach the file as attachment.

1 Like

Thank you Olaf

I was meant to say this works on a local PC, how do I change it to run for multiple remote PC’s

Either from a list inside the script or text files in a shared location

Get-CimInstance has the parameter -ComputerName which you can provide a list of computernames.

1 Like