Powershell get-hotfix and export-csv

Soldato
Joined
8 Mar 2005
Posts
3,676
Location
London, UK
I'm truly struggling today;

Feeder file with list of servers
Prompt for KB<numeric>
Checks whether HFB has been applied and reports installer and date details and then exports to simple CSV.

It's pretty much a simple one-liner but I'm going around in circles with the export!

Currently

Code:
Clear-Host
$Machines = "C:\windows\servers.txt"
$Patch = "KB2922229";
#$Patch;Read-Host 'KB<numeric<>'
$Computers = Get-Content $Machines
$temp = $null

ForEach ($Item in $Computers) 
{

$temp +=,(Get-Hotfix $Patch -ComputerName $Item | Select PSComputerName, HotfixID, Description, InstalledBy, InstalledOn | sort InstalledOn) 
}

$path = $temp | Export-Csv 'c:\output.csv'

OK, so this dumps out what I need, however I would like to include rows where the patch isn't installed and also where the server is unavailable/non-reportable.

Cheers, Paul.
 
Last edited:
Associate
Joined
3 Apr 2007
Posts
1,719
Location
London
You're exporting the file each time it loops.

You could look at adding -NoClobber and -NoTypeInformation as switches on the export but the better way to do it, imo, would be to compile the results into another variable and then sort/export that at the end.

So something like....

Code:
Clear-Host
$Machines = "C:\windows\servers.txt"
$Patch = "KB2922229";
#$Patch;Read-Host 'KB<numeric<>'
$Computers = Get-Content $Machines

[array]$Results = $null

ForEach ($Item in $Computers) 
{
	$Results += Get-Hotfix $Patch -ComputerName $Item
}

$Reults | 
	Select PSComputerName, HotfixID, Description, InstalledBy, InstalledOn | 
		sort InstalledOn | 
			Export-Csv 'c:\output.csv' -NoTypeInformation

... should work.
 
Soldato
OP
Joined
8 Mar 2005
Posts
3,676
Location
London, UK
No thank you. I need the all assistance I can get! :)

I also need to include where the patch isn't installed and where the server is unreachable (for whatever reason).

Cheers, Paul.
 
Back
Top Bottom