Need help with this powershell script

Neelesh Kumar Tiwari 21 Reputation points
2021-05-12T16:10:56.253+00:00

I have run the below command to get the output that when was my machine last patched but also need how to get the KB details too and how can I export in csv from SCCM.

$lastpatch=Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object HotfixID, InstalledOn | Select-Object -first 1
"{0:MM/dd/yyyy}" -f $lastpatch.InstalledOn | Write-Output

When I run the below command to also get the HotfixID but I am not getting the result so can someone help me with it.

$lastpatch= Get-HotFix | Sort-Object InstalledOn -Descending | select-object -first 1 | Select-Object InstalledOn, HotfixID
"{0:MM/dd/yyyy}" -f $lastpatch.InstalledOn,$lastpatch.HotfixID | Write-Output

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,278 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 30,826 Reputation points
    2021-05-12T17:11:10.007+00:00

    You need "{1}" to print out the second field.

    $lastpatch= Get-HotFix | Sort-Object InstalledOn -Descending | select-object -first 1 | Select-Object InstalledOn, HotfixID
    "{0:MM/dd/yyyy} - {1}" -f $lastpatch.InstalledOn,$lastpatch.HotfixID | Write-Output