Q: How can I create a list of processor and memory information for all active computers in my Active Directory (AD)?
March 16, 2011
A. A client asked me for a quick way to get physical processor and memory information about machines that are still active in AD. I decided on a quick PowerShell command that lists all computers in the AD that have logged in within 30 days. I then fetched information about the hardware using WMI, as shown below. If you want to base this on the last time the computer account password was changed instead of logon, use passwordLastSet in the command below instead of lastLogonTimestamp. Notice that there are two commands. The first just sets a variable equal to 30 days ago, and this variable is then used in the second query.
lastLogon = (get-date).adddays(-30).ToFileTime()
Get-ADComputer -filter \{lastLogonTimestamp -gt $lastLogon\} | ForEach-Object \{get-wmiobject Win32_ComputerSystem -computer$_.name | select Name, NumberOfProcessors,NumberofLogicalProcessors,TotalPhysicalMemory\}
Below is example output on my network at home.
> lastLogon = (get-date).adddays(-30).ToFileTime()
> Get-ADComputer -filter \{lastLogonTimestamp -gt $lastLogon\} | ForEach-Object \{get-wmiobject Win32_ComputerSystem -computer $_.name | select Name, NumberOfProcessors,NumberofLogicalProcessors,TotalPhysicalMemory\}
Name NumberOfProcessors NumberofLogicalProc TotalPhysicalMemory
---- ------------------ ------------------- -------------------
SAVDALDC10 1 2 2346246144
SAVDALWKS01 1 8 12883247104
SAVDALCLIENT 1 2 2612584448
SAVDALDC11 1 2 1230561280
SAVDALSCVMM 1 2 1203298304
SAVDALTS01 1 2 1022943232
SAVDALRODC01 1 1 1106829312
SAVDALEX10 1 2 4294500352
SAVDALCM01 1 2 1985536000
SAVDALOM01 1 2 6441984000
SAVDALAPPV01 1 2 708370432
SAVDALBFS01 2 16 51476549632
SAVDALFS01 1 1 557375488
SAVDALCLIENT2 1 1 1207492608
SAVDALCB01 1 2 773382144
SAVDALCLIENT4 1 1 1211686912
SAVDALCLIENT3 1 1 1228464128
You can change what you list for anything in Win32_ComputerSystem class if you want different information, or even query other classes.
If you need to use different credentials for the WMI, also run the following command before the main Get-ADComputer command.
$cred = Get-Credential
To get the credentials from the user, add –Credential $cred to the Get-WmiObject command after the –computer $_.name. For example,
lastLogon = (get-date).adddays(-30).ToFileTime()
$cred = Get-Credential
Get-ADComputer -filter \{lastLogonTimestamp -gt $lastLogon\} | ForEach-Object \{get-wmiobject Win32_ComputerSystem -computer $_.name -credential $cred | select Name, NumberOfProcessors,NumberofLogicalProcessors,TotalPhysicalMemory\}
About the Author
You May Also Like