Category Archives: powershell

Removing patches or hotfixes from windows server remotely

Below is the powershell script you can use to remove patches/hotfixes from servers remotely :

if($args[0] -eq $null)
{
$servernamefile = “c:\serverlist.txt”;
$hotfixidfile= “c:\hotfixlist.txt”;
}
else
{
$servernamefile = $args[0];
$hotfixidfile = $args[1];
}

$info1 = get-content $servernamefile;
$info2 = get-content $hotfixidfile;

foreach ($hotfixid in $info2)
{

foreach ($computername in $info1)
{
$KBhotfix=”KB”+$hotfixid;
if ((get-hotfix -id $KBhotfix -computername $computername))
{
Write-Host $hotfixid ‘ found on’ $computername ‘, removing it……’;
wmic /node:$computername process call create “powershell wusa /uninstall /kb:$hotfixid /quiet /forcerestart”;
}

else
{
Write-Host $hotfixid ‘ not found on’ $computername ‘.’;
}
}

Start-Sleep -s 600;
}

Advertisements

Finding SCCM client health of windows servers

Below is powershell script you can use to find healthcheck of SCCM clients on servers remotely-

$comp = get-content serverlist.txt

$strFileResults = “sccmclientstatus.txt”

$strOffLinePCs = “offlineservers.txt”

$skipped = @()

$comp | foreach {

$Global:currentpc = $_

if (Test-Connection $currentpc -Quiet -Count 1)
{
$status = get-service -ComputerName $currentpc | where-object { $_.Name -eq “CcmExec”} |
ForEach-Object { $_.status}

$strLine = $currentpc + “,” + $status

$strLine | Out-File $strFileResults -append

Write-Host $currentpc”,”$status

}
else
{
$skipped += $currentpc
}

}

$skipped | Out-File $strOffLinePCs