Scriptet letar igenom alla datorer i ett AD efter en infillista med patchar (patches.txt)

patches.txt

KB3000483
KB3004375
KB3031432

osv.

# $dcs = Get-Content "DCs.txt"
$dcs = Get-ADComputer -filter * -Properties name,operatingsystem,canonicalname,description | Select-Object name,operatingsystem,canonicalname,description

$patches = Get-Content "patches.txt"
Out-File ./Patchstatus.csv
foreach ( $dc in $dcs )
{
$servertest = Test-Connection -ComputerName $dc.name -Count 1 -BufferSize 16 -ErrorAction 0 -Quiet
if ( $servertest -like $true )
{
foreach ( $patch in $patches )
{
$fix=""
try
{
$fix=Get-HotFix -id $patch -ComputerName $dc.name -ErrorAction Stop
}
catch [System.ArgumentException]
{
Write-Host "$($dc.name) saknar $patch" -ForegroundColor Red
Add-Content ./Patchstatus.csv "$($dc.name);$patch;saknas;$($dc.operatingsystem);$($dc.description);$($dc.canonicalname)"
}
if ($fix -notlike "")
{
$fix
Add-Content ./Patchstatus.csv "$($fix.pscomputername);$($fix.hotfixid);$($fix.installedon);$($dc.operatingsystem);$($dc.description);$($dc.canonicalname)"
}
}
}
else
{
Write-Host "$($dc.name) ingen kontakt med server" -ForegroundColor Yellow
Add-Content ./Patchstatus.csv "$($dc.name);;Ingen kontakt med server;$($dc.operatingsystem);$($dc.description);$($dc.canonicalname)"
}
}