bigbrother87 icon

AD Computer Info

bigbrother87 | PRO | 09/11/17 06:25:11 PM UTC | 0 ⭐ | 206 👁️ | Never ⏰ | []
PowerShell |

3.5 KB

|

None

|

0 👍

/

0 👎

<#
 
    Script to query system information on collection of AD computers in OU
    Created 8.11.15 by
 
#>
 
#Gets list of computers to scan system information for by grabbing all AD Computers in the appropriate OU
$Computers = Get-ADComputer -Filter * -Properties Name -SearchBase "OU=Computers,DC=contoso,DC=local" | Select-Object -Expand Name
 
#Prompts for a path to store finalized report
$Path = Read-Host "Enter the full path including name of where you want to store the report"
 
#Calls out Array to be used for object storage in memory to persist throughout ForEach loop
$Data = @()
 
 
ForEach ($Computer in $Computers) {
 
    #Pings computer to see if it is online
    If(Test-Connection -ComputerName $Computer -Count 1 -ErrorAction 0){
    
        #Queries WMI classes for each category
        $ComputerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer
        $ComputerBIOS = get-wmiobject Win32_BIOS -Computer $Computer
        $ComputerOS = get-wmiobject Win32_OperatingSystem -Computer $Computer
        $ComputerCPU = get-wmiobject Win32_Processor -Computer $Computer
        $ComputerHDD = Get-WmiObject Win32_LogicalDisk -ComputerName $Computer -Filter drivetype=3
        $IPV4 = Test-Connection -ComputerName $Computer -Count 1 | Select -ExpandProperty IPV4Address
        $OfficePro = get-wmiobject -class win32_product -ComputerName $Computer | Where-Object {$_.Name -Like "*Office Professional*"} | Select-Object -ExpandProperty Name
        $OfficeStandard = get-wmiobject -class win32_product -ComputerName $Computer | Where-Object {$_.Name -Like "*Office Standard*"} | Select-Object -ExpandProperty Name
 
        #Stores the values in the PS object to the array
        $Data += New-Object -TypeName PSObject -Property @{
 
            ComputerName = $ComputerSystem.Name;
            Model = $ComputerSystem.Model;
            ServiceTag = $ComputerBIOS.SerialNumber;
            CPU = $ComputerCPU.Name;
            HDDCapacity = "{0:N2}" -f ($ComputerHDD.Size/1GB) + "GB";
            HDDFreeSpace = "{0:P2}" -f ($ComputerHDD.FreeSpace/$ComputerHDD.Size) + " Free (" + "{0:N2}" -f ($ComputerHDD.FreeSpace/1GB) + "GB)";
            RAM = "{0:N2}" -f ($ComputerSystem.TotalPhysicalMemory/1GB) + "GB";
            OS = $ComputerOS.caption + $ComputerOS.OSArchitecture + ", Service Pack: " + $ComputerOS.ServicePackMajorVersion;
            UserLastLoggedIn = $ComputerSystem.UserName;
            LastReboot = $ComputerOS.ConvertToDateTime($ComputerOS.LastBootUpTime);
            IPAddress = $IPV4.IPAddressToString;
            OfficeVersion = $OfficePro + $OfficeStandard}
 
    }
    
    #If the computer is not reachable fill values with OFFLINE
    Else{
 
            $Data += New-Object -TypeName PSObject -Property @{
 
                ComputerName = $Computer;
                Model = "Offline";
                ServiceTag = "Offline";
                CPU = "Offline";
                HDDCapacity = "Offline";
                HDDFreeSpace = "Offline";
                RAM = "Offline";
                OS = "Offline";
                UserLastLoggedIn = "Offline";
                LastReboot = "Offline";
                IPAddress = "Offline";
                OfficeVersion = "Offline"}
 
        }
 
}
#Exports all values in the array to CSV to the specified path
$Data | Select-Object ComputerName, Model, OS, ServiceTag, CPU, HDDCapacity, HDDFreeSpace, RAM, UserLastLoggedIn, LastReboot, IPAddress, OfficeVersion | Export-Csv -LiteralPath $Path -NoTypeInformation

Comments