Skip to content

Instantly share code, notes, and snippets.

@AlexAsplund
Created February 17, 2018 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexAsplund/127d59770f652be8ae5f4a46e5fd59a6 to your computer and use it in GitHub Desktop.
Save AlexAsplund/127d59770f652be8ae5f4a46e5fd59a6 to your computer and use it in GitHub Desktop.
Fetches info about windows updates, hotfixes and windows version
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