$logPath = "\\<ファイルサーバー名またはIPアドレス>\<共有名>\logs\wuscan_$(hostname).csv" $scancabPath = "\\<ファイルサーバー名またはIPアドレス>\<共有名>\wsusscn2.cab" if (Test-Path $scancabPath) { Write-Host "Scanning start using $scancabPath ..." Copy-Item $scancabPath "$env:Temp\mywsusscn2.cab" -Force $scancabPath = "$env:Temp\mywsusscn2.cab" #pause } else { Write-Host $scancabPath "not found. Nothing to do." #pause exit 1 } $UpdateSession = New-Object -ComObject Microsoft.Update.Session $UpdateServiceManager = New-Object -ComObject Microsoft.Update.ServiceManager $UpdateService = $UpdateServiceManager.AddScanPackageService("Offline Sync Service", $scancabPath) $UpdateSearcher = $UpdateSession.CreateUpdateSearcher() Write-Host "Searching for updates..." $UpdateSearcher.ServerSelection = 3 # ssOthers $UpdateSearcher.ServiceID = [string] $UpdateService.ServiceID $SearchResult = $UpdateSearcher.Search("IsInstalled=0") $Updates = $SearchResult.Updates Remove-Item $scancabPath If ($SearchResult.Updates.Count -eq 0) { Write-Host "There are no applicable updates." #pause exit 0 } Write-Host "List of applicable items on the machine when using wssuscan.cab:" $results = @() For ($i = 0; $i -lt $SearchResult.Updates.Count; $i++) { $update = $SearchResult.Updates.Item($i) Write-Host ($i + 1) "> " $update.Title $kbID = "" if ($update.Title -match 'KB\d{6,7}') { $kbID = $matches[0] } $results += [PSCustomObject]@{ Title = $update.Title KBid = $kbID Support = "https://support.microsoft.com/kb/" + $kbID.Substring(2) Catalog = "https://catalog.update.microsoft.com/Search.aspx?q=" + $kbID } } $results | Export-Csv -Path $logPath -NoTypeInformation -Encoding UTF8 #pause exit 0