[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer("localhost",$False)
$groupall = $wsus.GetComputerTargetGroups()
$pcall = $groupall | %{$_.GetComputerTargets()}
# Удаляем из групп
$groupall | %{
$group = $_
$pc_target = $_.GetComputerTargets()
$g = $_.name -replace '\w+ (\d+)(.+)?','$1'
if ($g.length -le 3){
$pc_target | %{
$p = $_;
$ip = $_.IPAddress.IPAddressToString -replace '172.16.(\d+)\.\d+','$1';
if ($g -eq $ip){
# write-host $p.FullDomainName "("$p.IPAddress")" "==>" $g -foregroundcolor gray
}
else {
write-host "Cur target:" $g "; PC Info:" $p.FullDomainName "("$p.IPAddress")" -foregroundcolor red
$client = $wsus.GetComputerTargetByName($p.FullDomainName)
$group.RemoveComputerTarget($client)
}
}
}
}
# Добавляем в группы
$group_un = $wsus.GetComputerTargetGroups() | ?{$_.id -eq "b73ca6ed-5727-47f3-84de-015e03f6a88a"}
$pc_un = $group_un.GetComputerTargets()
$pc_un | %{
$p = $_; $ip = $_.IPAddress.IPAddressToString -replace '172.16.(\d+)\.\d+','$1';
$groupall | %{
$n = $_.name -replace '\w+ (\d+)(.+)?','$1'
if ($n -eq $ip){
write-host $p.FullDomainName "("$p.IPAddress")" "==>" $_.name;
$_.AddComputerTarget($p)
}
}
}