PoshCode Archive  Artifact [6cb9de02a7]

Artifact 6cb9de02a787a05fe05954b5c68c00aa41192de00f012842db9b29821c1ce7df:

  • File Am-I-a-purist.ps1 — part of check-in [60847d4d9a] at 2018-06-10 12:56:32 on branch trunk — PS1 script to launch gpupdate on all computers in domain, without some stupid QAD cmdlets, just pure PS1 and WMI (user: unknown size: 1752)

# encoding: ascii
# api: powershell
# title: Am I a purist?
# description: PS1 script to launch gpupdate on all computers in domain, without some stupid QAD cmdlets, just pure PS1 and WMI
# version: 0.1
# type: script
# license: CC0
# x-poshcode-id: 1141
# x-archived: 2009-10-25T12:26:47
#
#
###########
# PS1 script to launch gpupdate on all computers in domain, without some stupid QAD cmdlets, just pure PS1 and WMI
# Made by pan_2@LJ (gunkan@yandex.ru)
# Note: if by some reason RPC host was unavaible - there will be exception throwed, I didn't use trap so I can see real reason.
###########
function PingComputer ([string]$Compname)
{
$pingvar  = Get-WmiObject -Class Win32_PingStatus -Filter "Address='$Compname'"
if ($pingvar.STatusCode -eq 0) {return $True} else {return $False}
}

function SearchAD ()
{
$strFilter = "(objectCategory=Computer)"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter

$colProplist = "name"

foreach ($i in $colPropList)
	{ 
	$null = $objSearcher.PropertiesToLoad.Add($i) 
	}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
	{
	$objItem = $objResult.Properties; 
	[string]$str = ""
	$str = $objItem.name
	$str
	}
}


foreach($str in SearchAD )
{
Write-host "Now trying... $str " -nonew
if (PingComputer $str)
	{
	if ( (([WMICLASS]"\\$str\ROOT\CIMV2:win32_process").Create("gpupdate.exe").ReturnValue) -eq 0) {write-host " succesfully!" -fo Green} else {write-host "failed!" -fo Red} 
	}
	else
	{ write-host "not responding..." -fo yellow}
}