Created
February 17, 2018 19:14
-
-
Save AlexAsplund/127d59770f652be8ae5f4a46e5fd59a6 to your computer and use it in GitHub Desktop.
Fetches info about windows updates, hotfixes and windows version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory=$True,Position=0)] | |
[Array]$ComputerName, | |
[Parameter(Mandatory=$True,Position=1)] | |
[String]$OutFile, | |
[Parameter(Position=2)] | |
[PSCredential]$Credential | |
) | |
$ScriptBlock = { | |
$WMIOperatingSystem = Get-WmiObject win32_OperatingSystem | |
$WindowsCaption = $WMIOperatingSystem.Caption | |
$WindowsVersion = $WMIOperatingSystem.Version | |
$Session = New-Object -ComObject Microsoft.Update.Session | |
$Searcher = $Session.CreateUpdateSearcher() | |
$Results = $Searcher.Search("IsInstalled = 1") | |
$WU = $Results.Updates | select Title,KBArticleIDs | |
$QuickFixes = Get-WmiObject -Class Win32_QuickFixEngineering | Select HotFixID,InstalledOn | |
$ComputerInfo = @{ | |
ComputerName = $env:COMPUTERNAME | |
FetchedOnDate = (Get-Date -Format "yyyy-MM-dd HH:mm:ss") | |
OperatingSystemCaption = $WindowsCaption | |
OperatingSystemVersion = $WindowsVersion | |
UpdatesInstalled = $WU | |
QuickFixes = $QuickFixes | |
} | |
return $ComputerInfo | |
} | |
if($Credential -ne $null){ | |
$CredentialSplat = @{ | |
Credential = $Credential | |
} | |
} | |
else { | |
$CredentialSplat = @{} | |
} | |
$Job = Invoke-Command -ComputerName $ComputerName -AsJob -JobName WindowsUpdateFetch -ScriptBlock $ScriptBlock @CredentialSplat | |
$Job | Wait-Job | |
$JobResult = $Job | Receive-Job | |
$JobResult | ConvertTo-Json | Out-File -FilePath $OutFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment