Using hotfix in for each loop

Good morning experts!
Looking for some help to use hotfix to grab servername, kb number and date into one file so I can compare them. Here is what we have so far

$admin=Get-Credential
$Servers=Get-Content C:\WVUS\SQL_Servers.txt
$date=[datetime]::Today.ToString('MM-dd-yyyy')

 


ForeEach ($Server in $Servers) {
Invoke-Command -ComputerName $Server -ScriptBlock { "$(Get-HotFix)" } -Credential $admin | Out-File -filepath c:\Temp\SQL_SERVERS_KB_$date.txt -Append
}

Thanks in advance for your input

Norm

a generic advice,

Just write code to get hotfix from the localmachine in the desired output format. Once ready, then us Invoke-Command to target multiple computers.

PS: Get-Hotfix do have a -ComputerName parameter, using that’ll will be better here.

Get-HotFix -ComputerName (Get-Content -Path <computerlist.txt>) | Export-CSV <csvpath.csv> -NoTypeInformation