I've made a simple script that obtains patching information from a series of servers.
The csv file I use to reference my servers is called patchlevels.csv and just contains some basic information.
ServerName,OS,ServicePack,Patches,,,,,,, SERVER1,Server 2003 R2 Enterprise,SP2,,,,,,,, SERVER2,Server 2003 R2 Enterprise X64 Edition,SP2,,,,,,,,
Yup, that's exactly as its formatted ^
The problem I am having is updating the Patches column with a link to the server-specific htm file (I figure I can always save as xlsx within Excel to get clickable hyperlinks). I have failed multiple times over the last few hours using export-csv to try and update the Patches cell(s).
Here is my script minus any failed export-csv references for clarity's sake:
$currentPath = "$pwd\" $HostFileName = "patchlevels.csv" $CSVLoc = $currentPath + $HostFileName Import-Csv "$CSVLoc" | ForEach-Object { Write-Host "Processing..." Write-Host "------------------------------------------------------------" -ForegroundColor Yellow $ServerName=$_.ServerName $ServerFile = "$ServerName.htm" $OS=$_.OS $ServicePack=$_.ServicePack $_.Patches = $_.Patches.replace("[","$ServerFile") Write-Host "Server Name: $ServerName" Write-Host "Operating System: $OS" Write-Host "Service Pack: $ServicePack" Write-Host "Processing Patch List" wmic /node:$ServerName /output:$ServerName.htm qfe list Write-Host "Patch List generated for $ServerName" Write-Host "------------------------------------------------------------" -ForegroundColor Yellow } Write-Host "END PROCESSING"
I can see two things that may be wrong:
1) Formatting of my CSV file (,,,,,,)
2) I am not sure about the formatting of $_.Patches = $_.Patches.replace("[","$ServerFile")
And obviously, I'm missing the export-csv commands to update the patchlevels.csv file with the htm file location (which is what this entire post is about).
Where would I put export-csv in this code to update my original csv as the script runs?
Thanks in advance for any help with this.
Kind Regards,
Stephen