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
runs.
4. If the ping is not successfull then it writes the machines name to
another file.
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)"
$searcher.pageSize=1000
$searcher.propertiesToLoad.Add("name")
$computers = $searcher.findall()
foreach ($computer in $computers)
{
$computername = $computer.properties.name
$ping = gwmi win32_pingstatus -f "Address = '$computername'"
if ($ping.StatusCode -eq 0)
{
$registry =
[Microsoft.Win32.RegistryKey]:

penRemoteBaseKey("LocalMachine","$computername")
$registrykey = $registry.openSubKey("Software\Microsoft\Windows
NT\CurrentVersion\Winlogon")
$LastUser = $registrykey.getValue("DefaultUserName")
$OS = (gwmi Win32_OperatingSystem -computername $computername).caption
$InstalledMemory = (gwmi win32_ComputerSystem -computername
$computername).TotalPhysicalmemory/1024000000
$FreeDiskSpace = (gwmi win32_logicaldisk -computername $computername -filter
"Name='c:'").freespace/1075000000
$IPAddress = $ping.ProtocolAddress
out-file \\Servername\sharename\ScanningResults.csv -inputobject
"$LastUser $computername $IPAddress $OS $InstalledMemory $FreeDiskSpace"
-append
"$Computername -- $OS"
}
Else
{
out-file \\Servername\sharename\PingFailedResults.csv
-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.
Jacob Sampson
jsampson@xxxxxx