Powershell Assistance

5 pts.
Tags:
Scripting
New to Powershell and tyring to modify the below script to check if the current months MS patches are installed. Script is designed to check the $filename.mbsa and the Patches_NA.txt file and send results to $env:ComputerName.csv file.




Software/Hardware used:
Function Check-Patches{ Param($Filename) $logname = "C:\temp\PatchVerify\$FileName.csv" [xml]$x=type "C:\Users\Cambridge\SecurityScans\$FileName.mbsa" $PatchStatus = @() #This list is created based on a text file that is provided. #$monthlyPatches = GC "C:\Temp\PatchVerify\Patches_NA.txt"|?{$_ -match "-KB(? \d+)"} | %{$matches.KB} $monthlypatches -contains $_.KBID instead of $_.KBID -in $monthlypatches #Create objects for all the patches in the updatelog that were in the monthly list. Switch($x.SecScan.Check|?{$_.KBID -in $monthlyPatches -and $_.id -eq 500}){ {$_.detail.updatedata.isinstalled -eq "true"}{$PatchStatus+=[PSCustomObject][Ordered]@{Store=$FileName;Patch=$_.KBID;Present="YES"};Continue} {$_.detail.updatedata.isinstalled -eq "false"}{$PatchStatus+=[PSCustomObject][Ordered]@{Store=$FileName;Patch=$_.KBID;Present="NO"};Continue} } #Populate all of the monthly patches that weren't found on the machine as installed or failed $monthlypatches | ?{$_ -notin $PatchStatus.Patch} | %{$PatchStatus += [PSCustomObject][Ordered]@{Store=$FileName;Patch=$_;Present="Unknown"}} #Output results $PatchStatus } #Check patches on current computer Check-Patches "$env:ComputerName"|Export-Csv "C:\temp\PatchVerify\$env:ComputerName.csv" -NoTypeInformation #Check patches on POS Devices For($i=1;$i -le 60;$i++){ Check-Patches "172.26.210.$i"|Export-Csv "C:\temp\PatchVerify\172.26.210.$i.csv" -NoTypeInformation }

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following