SHOW:
|
|
- or go back to the newest paste.
| 1 | <# | |
| 2 | ||
| 3 | Script to query system information on collection of AD computers in OU | |
| 4 | Created 8.11.15 by | |
| 5 | ||
| 6 | #> | |
| 7 | ||
| 8 | #Gets list of computers to scan system information for by grabbing all AD Computers in the appropriate OU | |
| 9 | $Computers = Get-ADComputer -Filter * -Properties Name -SearchBase "OU=Computers,DC=contoso,DC=local" | Select-Object -Expand Name | |
| 10 | ||
| 11 | #Prompts for a path to store finalized report | |
| 12 | $Path = Read-Host "Enter the full path including name of where you want to store the report" | |
| 13 | ||
| 14 | #Calls out Array to be used for object storage in memory to persist throughout ForEach loop | |
| 15 | $Data = @() | |
| 16 | ||
| 17 | ||
| 18 | ForEach ($Computer in $Computers) {
| |
| 19 | ||
| 20 | #Pings computer to see if it is online | |
| 21 | If(Test-Connection -ComputerName $Computer -Count 1 -ErrorAction 0){
| |
| 22 | ||
| 23 | #Queries WMI classes for each category | |
| 24 | $ComputerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer | |
| 25 | $ComputerBIOS = get-wmiobject Win32_BIOS -Computer $Computer | |
| 26 | $ComputerOS = get-wmiobject Win32_OperatingSystem -Computer $Computer | |
| 27 | $ComputerCPU = get-wmiobject Win32_Processor -Computer $Computer | |
| 28 | $ComputerHDD = Get-WmiObject Win32_LogicalDisk -ComputerName $Computer -Filter drivetype=3 | |
| 29 | $IPV4 = Test-Connection -ComputerName $Computer -Count 1 | Select -ExpandProperty IPV4Address | |
| 30 | $OfficePro = get-wmiobject -class win32_product -ComputerName $Computer | Where-Object {$_.Name -Like "*Office Professional*"} | Select-Object -ExpandProperty Name
| |
| 31 | $OfficeStandard = get-wmiobject -class win32_product -ComputerName $Computer | Where-Object {$_.Name -Like "*Office Standard*"} | Select-Object -ExpandProperty Name
| |
| 32 | ||
| 33 | #Stores the values in the PS object to the array | |
| 34 | $Data += New-Object -TypeName PSObject -Property @{
| |
| 35 | ||
| 36 | ComputerName = $ComputerSystem.Name; | |
| 37 | Model = $ComputerSystem.Model; | |
| 38 | ServiceTag = $ComputerBIOS.SerialNumber; | |
| 39 | CPU = $ComputerCPU.Name; | |
| 40 | HDDCapacity = "{0:N2}" -f ($ComputerHDD.Size/1GB) + "GB";
| |
| 41 | HDDFreeSpace = "{0:P2}" -f ($ComputerHDD.FreeSpace/$ComputerHDD.Size) + " Free (" + "{0:N2}" -f ($ComputerHDD.FreeSpace/1GB) + "GB)";
| |
| 42 | RAM = "{0:N2}" -f ($ComputerSystem.TotalPhysicalMemory/1GB) + "GB";
| |
| 43 | OS = $ComputerOS.caption + $ComputerOS.OSArchitecture + ", Service Pack: " + $ComputerOS.ServicePackMajorVersion; | |
| 44 | UserLastLoggedIn = $ComputerSystem.UserName; | |
| 45 | LastReboot = $ComputerOS.ConvertToDateTime($ComputerOS.LastBootUpTime); | |
| 46 | IPAddress = $IPV4.IPAddressToString; | |
| 47 | OfficeVersion = $OfficePro + $OfficeStandard} | |
| 48 | ||
| 49 | } | |
| 50 | ||
| 51 | #If the computer is not reachable fill values with OFFLINE | |
| 52 | Else{
| |
| 53 | ||
| 54 | $Data += New-Object -TypeName PSObject -Property @{
| |
| 55 | ||
| 56 | ComputerName = $Computer; | |
| 57 | Model = "Offline"; | |
| 58 | ServiceTag = "Offline"; | |
| 59 | CPU = "Offline"; | |
| 60 | HDDCapacity = "Offline"; | |
| 61 | HDDFreeSpace = "Offline"; | |
| 62 | RAM = "Offline"; | |
| 63 | OS = "Offline"; | |
| 64 | UserLastLoggedIn = "Offline"; | |
| 65 | LastReboot = "Offline"; | |
| 66 | IPAddress = "Offline"; | |
| 67 | OfficeVersion = "Offline"} | |
| 68 | ||
| 69 | } | |
| 70 | ||
| 71 | } | |
| 72 | #Exports all values in the array to CSV to the specified path | |
| 73 | $Data | Select-Object ComputerName, Model, OS, ServiceTag, CPU, HDDCapacity, HDDFreeSpace, RAM, UserLastLoggedIn, LastReboot, IPAddress, OfficeVersion | Export-Csv -LiteralPath $Path -NoTypeInformation |