In an effort to be as valuable to this community as it has been to me I am
posting this script. I hope that it will be usefull to some. If this is the
wrong place to do this sort of thing feel free to move it.
Here is what the script does:
1. Gathers all computers in your Active Directory Domain and loads them into
a variable (maybe an array I am not sure.)
2. Cycles through the array of computernames one by one and Pings them. If
the ping is successfull then it gets the following info from that machine:
a. Last logged on username
b. Computer name
c. what the OS is
d. how much memory is installed
e. What the Ip address is of the machine
f. how much free space is left on the C:\
3. It then writes this info to a tab seperated .csv file. It also write the
computername and OS to the screen so that you can monitor the script as it
4. If the ping is not successfull then it writes the machines name to
This seems like it would be valuable from the standpoint of monitoring
resources on your network as well as Cleaning out the guts of my script and
putting your own guts in but already having the engine to scan all machines
in any domain.
$root = [ADSI]''
$searcher = new-object System.DirectoryServices.DirectorySearcher($root)
$searcher.filter = "(objectCategory=computer)"
$computers = $searcher.findall()
foreach ($computer in $computers)
$computername = $computer.properties.name
$ping = gwmi win32_pingstatus -f "Address = '$computername'"
if ($ping.StatusCode -eq 0)
$registrykey = $registry.openSubKey("Software\Microsoft\Windows
$LastUser = $registrykey.getValue("DefaultUserName")
$OS = (gwmi Win32_OperatingSystem -computername $computername).caption
$InstalledMemory = (gwmi win32_ComputerSystem -computername
$FreeDiskSpace = (gwmi win32_logicaldisk -computername $computername -filter
$IPAddress = $ping.ProtocolAddress
out-file \\Servername\sharename\ScanningResults.csv -inputobject
"$LastUser $computername $IPAddress $OS $InstalledMemory $FreeDiskSpace"
"$Computername -- $OS"
-inputobject "$computername" -append
P.S. After pasting this in I realized it is very ugly. There are many times
where lines are split in two. If you have any questions about the script or
would like me to email you a cleaner version feel free to send me an email.