################################################################################## # # # Script name: Get-Inventory.ps1 # Author: goude@powershell.nu # Homepage: www.powershell.nu # # ################################################################################## param ([string]$Client, [switch]$help) function GetHelp() { $HelpText = @" DESCRIPTION: NAME: Get-Inventory.ps1 Gets Information About Clients through WMI PARAMETERS: -Client Name of the Client (Required) -help Prints the HelpFile (Optional) SYNTAX: ./Get-Inventory.ps1 -Client Client1 Gets Information about the client and returns it to the Prompt Get-Inventory.ps1 -help Displays the help topic for the script "@ $HelpText } function Get-ChassisType ($Type) { # Function that calculates ChassisType # based on Win32_SystemEnclosure # thanks, Scripting Guy # http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0921.mspx Switch($Type) { { $_ -eq 1 } { "Maybe Virtual Machine” } { $_ -eq 2 } { "??” } { $_ -eq 3 } { "Desktop” } { $_ -eq 4 } { "Thin Desktop” } { $_ -eq 5 } { "Pizza Box” } { $_ -eq 6 } { "Mini Tower” } { $_ -eq 7 } { "Full Tower” } { $_ -eq 8 } { "Portable” } { $_ -eq 9 } { "Laptop” } { $_ -eq 10 } { "Notebook” } { $_ -eq 11 } { "Hand Held” } { $_ -eq 12 } { "Docking Station” } { $_ -eq 13 } { "All in One” } { $_ -eq 14 } { "Sub Notebook” } { $_ -eq 15 } { "Space-Saving” } { $_ -eq 16 } { "Lunch Box” } { $_ -eq 17 } { "Main System Chassis” } { $_ -eq 18 } { "Lunch Box” } { $_ -eq 19 } { "SubChassis” } { $_ -eq 20 } { "Bus Expansion Chassis” } { $_ -eq 21 } { "Peripheral Chassis” } { $_ -eq 22 } { "Storage Chassis" } { $_ -eq 23 } { "Rack Mount Unit” } { $_ -eq 24 } { "Sealed-Case PC” } Default { ”Unknown” } } } function Get-ClientInformation ([string]$ComputerName) { Write-Host "Gathering Client Information From: $ComputerName" # WMI Used in Script $WmiObject = "ComputerSystem", "OperatingSystem", "NetworkAdapterConfiguration", "SystemEnclosure", "LogicalDisk", "Processor", "DisplayConfiguration" # Gathering Information ForEach WMI object # And Storing in Variable $WmiObject $WmiObject | % { Set-Variable -name $_ -value (gwmi Win32_$_ -ComputerName $ComputerName) } # Get Network Information $NetworkAdapter = $NetworkAdapterConfiguration | where {$_.Index -match $Network.DeviceID -and $_.IPEnabled -eq $true } | select -first 1 $IPAddress = ($NetworkAdapter.IpAddress | select -first 1).ToString() $IPSubNet = ($NetworkAdapter.IPSubnet | select -first 1).ToString() $MACAddress = $NetworkAdapter.MACAddress # Get ChassisType $ChassisValue = $SystemEnclosure.ChassisTypes $ChassisType = Get-ChassisType $ChassisValue # Get OperatingSystem and Language $OS = ($OperatingSystem.Caption).ToString() $OSLanguage = ($OperatingSystem.OSLanguage).ToString() # Get RAM [int]$RAM = ($OperatingSystem.TotalVisibleMemorySize / 1024) $RAMMemory = [string]$RAM + " MB" # Get HD Size $HDD = $LogicalDisk | Where { $_.DeviceID -match "C:" } [int]$HDDTot = ($HDD.Size /1024 /1024) [int]$HDDFree = ($HDD.FreeSpace /1024 /1024) $HDTotal = [string]$HDDTot + " MB" $HDFreeSpace = [string]$HDDFree + " MB" # Create Object to hold information $ClientObject = New-Object PsObject $ClientObject | Add-Member -memberType NoteProperty "UserName" -Value $ComputerSystem.UserName $ClientObject | Add-Member -memberType NoteProperty "ComputerName" -Value $ComputerSystem.Name $ClientObject | Add-Member -memberType NoteProperty "ScreenModel" -Value $DisplayConfiguration.DeviceName $ClientObject | Add-Member -memberType NoteProperty "ChassisType" -Value $ChassisType $ClientObject | Add-Member -memberType NoteProperty "ComputerManufacturer" -Value $ComputerSystem.Manufacturer $ClientObject | Add-Member -memberType NoteProperty "ComputerModel" -Value $ComputerSystem.Model $ClientObject | Add-Member -memberType NoteProperty "SerialNumber" -Value $OperatingSystem.SerialNumber $ClientObject | Add-Member -memberType NoteProperty "RAM" -Value $RAMMemory $ClientObject | Add-Member -memberType NoteProperty "CPU" -Value $Processor.Name $ClientObject | Add-Member -memberType NoteProperty "HDDTotal" -Value $HDTotal $ClientObject | Add-Member -memberType NoteProperty "HDDFreeSpace" -Value $HDFreeSpace $ClientObject | Add-Member -memberType NoteProperty "OperatingSystem" -Value $OS $ClientObject | Add-Member -memberType NoteProperty "Language" -Value $OSLanguage $ClientObject | Add-Member -memberType NoteProperty "Domain" -Value $ComputerSystem.Domain $ClientObject | Add-Member -memberType NoteProperty "IPAdress" -Value $IPAddress $ClientObject | Add-Member -memberType NoteProperty "SubNet" -Value $IPSubNet $ClientObject | Add-Member -memberType NoteProperty "MACAddress" -Value $MACAddress # Return Information return $ClientObject } if ($help) { GetHelp } if ($Client) { Get-ClientInformation $Client }