question

NeeleshTiwari-7891 avatar image
0 Votes"
NeeleshTiwari-7891 asked IanXue-MSFT commented

Need help with this powershell script

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
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

If the reply is helpful, please “Accept Answer” to help other community members find it more easily,

0 Votes 0 ·

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered NeeleshTiwari-7891 commented

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
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you @MotoX80 this will help and get the write output.
Thank you again:)

0 Votes 0 ·