# Get list of Server OS versions and last reboot date

**URL:** <https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952>\
**Category:** PowerShell Help\
**Created:** [June 30, 2021, 8:10am UTC](https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952 "2021-06-30T08:10:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![app.support](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@app.support](https://forums.powershell.org/u/app.support)\
**Post date:** [June 30, 2021, 8:10am UTC](https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952/1 "2021-06-30T08:10:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 30, 2021, 9:18am UTC](https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952/2 "2021-06-30T09:18:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![app.support](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@app.support](https://forums.powershell.org/u/app.support)\
**Post date:** [June 30, 2021, 10:53am UTC](https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952/3 "2021-06-30T10:53:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![app.support](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@app.support](https://forums.powershell.org/u/app.support)\
**Post date:** [June 30, 2021, 10:58am UTC](https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952/4 "2021-06-30T10:58:07Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 30, 2021, 11:04am UTC](https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952/5 "2021-06-30T11:04:34Z")

</div>

> [@app.support](#):
>
> 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

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.

---

<div class="post-metadata">

**Author:** ![app.support](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@app.support](https://forums.powershell.org/u/app.support)\
**Post date:** [June 30, 2021, 11:44am UTC](https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952/6 "2021-06-30T11:44:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 30, 2021, 12:11pm UTC](https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952/7 "2021-06-30T12:11:02Z")

</div>

> [@app.support](#):
>
> how do I change it to run for multiple remote PC’s

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:23pm UTC](https://forums.powershell.org/t/get-list-of-server-os-versions-and-last-reboot-date/16952/8 "2024-05-16T20:23:57Z")

</div>


