During a recent ConfigMgr side by side migration project I was asked to provide a reliable way to return AD Site and SCCM site code information for each computer in an OU. The below PowerShell script is what i came up with.
The script will return Name, ADSite and SCCM site code information for each computer within the Active Directory OU defined in the variable ‘$searchbase’ .
As the ‘Invoke-WMIMethod’ method has no reliable way to timeout quickly, i first test connectivity to each machine with a simple 1 packet ping (Test-Connection –ComputerName $i –Quiet –Count 1) if the ping fails, it will not attempt a WMI connection.
A progress bar will track and show computer counts, finally results including error codes are stored in the $result variable.