# I'd like to get the latest update installed and the OS version of a list of computers

**URL:** <https://forums.powershell.org/t/id-like-to-get-the-latest-update-installed-and-the-os-version-of-a-list-of-computers/18093>\
**Category:** PowerShell Help\
**Created:** [December 1, 2021, 2:23pm UTC](https://forums.powershell.org/t/id-like-to-get-the-latest-update-installed-and-the-os-version-of-a-list-of-computers/18093 "2021-12-01T14:23:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackjack](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/blackjack/32/1916_2.png) [@blackjack](https://forums.powershell.org/u/blackjack)\
**Post date:** [December 1, 2021, 2:23pm UTC](https://forums.powershell.org/t/id-like-to-get-the-latest-update-installed-and-the-os-version-of-a-list-of-computers/18093/1 "2021-12-01T14:23:56Z")

</div>

Hi,

I’m new to the forum and pretty noob in regards to PowerShell.

I need to retrieve the following information from a list of servers:

- the OS version
- the latest update installed

I found the following scripts:

```auto
Get-Content "C:\Temp\Computers.txt" | ForEach-Object{
$os_name=$null
$os_version=$null
$errorMsg=''
Try
{
$os_name = (Get-WmiObject Win32_OperatingSystem -ComputerName $_ ).Caption
}
catch
{
$errorMsg=$_.Exception.Message
}
if(!$os_name){
$os_name = "The machine is unavailable $errorMsg"
$os_version = "The machine is unavailable"
}
else{
$os_version = (Get-WmiObject Win32_OperatingSystem -ComputerName $_ ).Version 
}
New-Object -TypeName PSObject -Property @{
ComputerName = $_
OSName = $os_name
OSVersion = $os_version 
}} | Select ComputerName,OSName,OSVersion | 
Export-Csv "C:\Temp\OS_Details.csv" -NoTypeInformation -Encoding UTF8

```

and

```auto
(Get-HotFix | Sort-Object -Property InstalledOn)[-1]

```

How can i get those two scripts to be one and have all the information in the outpule CSV file formatted like:

ComputerName - OSName - OSVersion - Latest update installed?

Thanks in advance for your help. 🙂

---

<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:** [December 1, 2021, 4:31pm UTC](https://forums.powershell.org/t/id-like-to-get-the-latest-update-installed-and-the-os-version-of-a-list-of-computers/18093/2 "2021-12-01T16:31:44Z")

</div>

Dominique,  
Welcome to the forum. 👋🏽

You can use a PSCustomObject to combine the output of two or more commands into one result.

```auto
$ServerList = Get-Content -Path 'C:\Temp\Computers.txt'
$Result = 
foreach ($ComputerName in $ServerList) {
    Invoke-Command -ComputerName $ComputerName -ScriptBlock {
        $OS = Get-CimInstance -ClassName CIM_OperatingSystem
        $HF = Get-HotFix | Sort-Object -Property InstalledOn | Select-Object -Last 1
        [PSCustomObject]@{
            ComputerName = $ENV:COMPUTERNAME
            OS = $OS.Caption
            Version = $OS.Version
            LastHotfix = $HF.HotFixID
        }
    }
}
$Result | Select-Object -Property ComputerName, OS, Version, LastHotFix

```

Since `Get-HotFix` only returns the install date and not the install time you might not really get latest installed updates.

---

<div class="post-metadata">

**Author:** ![blackjack](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/blackjack/32/1916_2.png) [@blackjack](https://forums.powershell.org/u/blackjack)\
**Post date:** [December 1, 2021, 4:48pm UTC](https://forums.powershell.org/t/id-like-to-get-the-latest-update-installed-and-the-os-version-of-a-list-of-computers/18093/3 "2021-12-01T16:48:08Z")

</div>

Hello Olaf!  
Thanks for your answer.  
When I run this command: (Get-HotFix | Sort-Object -Property InstalledOn)[-1], I have the installation date:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/9/96262a3fc89228fe8b6ff86ac93185dd0aa96c8f.png)

Do you know if there a way to have this value?  
Also, can I add a pipe to have the results in a file?

Thank you very much!

---

<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:** [December 1, 2021, 5:00pm UTC](https://forums.powershell.org/t/id-like-to-get-the-latest-update-installed-and-the-os-version-of-a-list-of-computers/18093/4 "2021-12-01T17:00:54Z")

</div>

> [@blackjack](#):
>
> Do you know if there a way to have this value?

Do you want only the date or additionally? 😉

I understood from your initial post …

> [@blackjack](#):
>
> ComputerName - OSName - OSVersion - Latest update installed?

“What’s the latest update what’s been installed on the computer” and not “when was the lastest update installed” 😉

… and of course you can have anthing what’s returned by the command …

When you run the following command on your computer …

```auto
$HF = Get-HotFix | Sort-Object -Property InstalledOn | Select-Object -Last 1

```

You can get the HotFixID with the command

```auto
$HF.HotFixID

```

… as shown in my code suggestion. I’m sure you have an idea how to get the property “InstalledOn” instead of “HotFixID”. 👆🏽 😉

> [@blackjack](#):
>
> Also, can I add a pipe to have the results in a file?

Sure. You pipe the last command to whatever output cmdlet you like. Probably `Export-Csv` would make the most sense.

---

<div class="post-metadata">

**Author:** ![blackjack](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/blackjack/32/1916_2.png) [@blackjack](https://forums.powershell.org/u/blackjack)\
**Post date:** [December 1, 2021, 5:06pm UTC](https://forums.powershell.org/t/id-like-to-get-the-latest-update-installed-and-the-os-version-of-a-list-of-computers/18093/5 "2021-12-01T17:06:08Z")

</div>

> [@Olaf](#):
>
> Do you want only the date or additionally? 😉
> 
> I understood from your initial post …
> 
> > [@blackjack](#):
> >
> > ComputerName - OSName - OSVersion - Latest update installed?
> 
> “What’s the latest update what’s been installed on the computer” and not “when was the lastest update installed” 😉

You understand well, it’s me who did not express myself correctly. Sorry for that. I would like to have the installation date too actually.

Again thanks for your help, I’ll try this out in a bit. 🙂

---

<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:** [December 1, 2021, 5:45pm UTC](https://forums.powershell.org/t/id-like-to-get-the-latest-update-installed-and-the-os-version-of-a-list-of-computers/18093/6 "2021-12-01T17:45:30Z")

</div>

> [@blackjack](#):
>
> Again thanks for your help, I’ll try this out in a bit. 🙂

If you get stuck do not hesitate to come back. We all have been beginners once. 😉

---

<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:20pm UTC](https://forums.powershell.org/t/id-like-to-get-the-latest-update-installed-and-the-os-version-of-a-list-of-computers/18093/7 "2024-05-16T20:20:11Z")

</div>


