To get an inventory .csv file list of all computers in AD, run the following command in powershell:
Make sure you import Active Directory modules into PowerShell prior to running the command.
Get-ADComputer -Filter * -Property * | Select-Object Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion,ipv4* | Export-Csv -Path "c:\admin\ComputersList.csv"
If you first receive the following error:
“The term ‘Get-ADComputer’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.”
This error indicates that the Active Directory module has not been imported into PowerShell. First do this by running the command:
import-module activedirectory
This script should produce and export a .csv file list that looks like the following:
Name |
OperatingSystem |
OperatingSystemServicePack |
OperatingSystemVersion |
IPv4Address |
DC01 |
Windows Server 2008 R2 Standard |
Service Pack 1 |
6.1 (7601) |
10.1.3.4 |
|
|
|
|
|
JasonCWKS |
Windows 7 Professional |
Service Pack 1 |
6.1 (7601) |
10.1.2.129 |
JColtrinWin7 |
Windows 7 Professional |
Service Pack 1 |
6.1 (7601) |
10.1.2.85 |
If you want to take this further, and get the csname (computer name), caption (Operating system title), OS Architecture (32/64 bit), and ServicePackMajorVersion (service pack level) from a list of IP’s that the previous command produced you can do the following:
- Copy the IP addresses of all the machines to a new file called win7pcs.txt and place it in C:\admin\
- Open Powershell ISE and enter the following script:
$a = Get-Content "C:\admin\win7pcs.txt"
foreach ($i in $a)
{Get-WmiObject Win32_OperatingSystem -ComputerName $i | Format-Table csname,caption,OSArchitecture,ServicePackMajorVersion -AutoSize
}
This should produce the following output for each IP address:
…
csname caption OSArchitecture ServicePackMajorVersion
—— ——- ————– ———————–
JasonCWKS Microsoft Windows 7 Professional 64-bit 1
csname caption OSArchitecture ServicePackMajorVersion
—— ——- ————– ———————–
JcoltrinWin7 Microsoft Windows 7 Professional 32-bit 1