Situatie
How to get information on domain joined devices.
Solutie
$testcomputers = Get-Content -Path ‘d:\list2.txt’
$exportLocation = ‘d:\pcInventory2.csv’
# Test connection to each computer before getting the inventory info
foreach ($computer in $testcomputers) {
if (Test-Connection -ComputerName $computer -Quiet -count 2){
Add-Content -value $computer -path d:\list2.txt
}else{
Add-Content -value $computer -path c:\scripts\deadPCs2.txt
}
}
# Now that we know which PCs are live on the network
# proceed with the inventory
$computers = Get-Content -Path ‘d:\list2.txt’
foreach ($computer in $computers) {
$Bios = Get-WmiObject win32_bios -Computername $Computer
$Hardware = Get-WmiObject Win32_computerSystem -Computername $Computer
$Sysbuild = Get-WmiObject Win32_WmiSetting -Computername $Computer
$OS = Get-WmiObject Win32_OperatingSystem -Computername $Computer
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | Where-Object {$_.IPEnabled}
$driveSpace = Get-WmiObject win32_volume -computername $Computer -Filter ‘drivetype = 3′ |
Select-Object PScomputerName, driveletter, label, @{LABEL=’GBfreespace’;EXPRESSION={‘{0:N2}’ -f($_.freespace/1GB)} } |
Where-Object { $_.driveletter -match ‘C:’ }
$cpu = Get-WmiObject Win32_Processor -computername $computer
$username = Get-ChildItem “\\$computer\c$\Users” | Sort-Object LastWriteTime -Descending | Select-Object Name, LastWriteTime -first 1
$totalMemory = [math]::round($Hardware.TotalPhysicalMemory/1024/1024/1024, 2)
$lastBoot = $OS.ConvertToDateTime($OS.LastBootUpTime)
$installdate = ([WMI] “”).ConvertToDateTime((Get-WmiObject Win32_OperatingSystem -ComputerName $computer).InstallDate)
$IPAddress = $Networks.IpAddress[0]
$MACAddress = $Networks.MACAddress
$systemBios = $Bios.serialnumber
$OutputObj = New-Object -Type PSObject
$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
$OutputObj | Add-Member -MemberType NoteProperty -Name Manufacturer -Value $Hardware.Manufacturer
$OutputObj | Add-Member -MemberType NoteProperty -Name Model -Value $Hardware.Model
$OutputObj | Add-Member -MemberType NoteProperty -Name Processor_Type -Value $cpu.Name
$OutputObj | Add-Member -MemberType NoteProperty -Name System_Type -Value $Hardware.SystemType
$OutputObj | Add-Member -MemberType NoteProperty -Name Operating_System -Value $OS.Caption
$OutputObj | Add-Member -MemberType NoteProperty -Name Operating_System_Version -Value $OS.version
$OutputObj | Add-Member -MemberType NoteProperty -Name Operating_System_BuildVersion -Value $SysBuild.BuildVersion
$OutputObj | Add-Member -MemberType NoteProperty -Name Serial_Number -Value $systemBios
$OutputObj | Add-Member -MemberType NoteProperty -Name IP_Address -Value $IPAddress
$OutputObj | Add-Member -MemberType NoteProperty -Name MAC_Address -Value $MACAddress
$OutputObj | Add-Member -MemberType NoteProperty -Name Last_User -Value $username.Name
$OutputObj | Add-Member -MemberType NoteProperty -Name User_Last_Login -Value $username.LastWriteTime
$OutputObj | Add-Member -MemberType NoteProperty -Name C:_FreeSpace_GB -Value $driveSpace.GBfreespace
$OutputObj | Add-Member -MemberType NoteProperty -Name Total_Memory_GB -Value $totalMemory
$OutputObj | Add-Member -MemberType NoteProperty -Name Last_ReBoot -Value $lastboot
$OutputObj | Add-Member -MemberType NoteProperty -Name InstallDate -Value $installdate
$OutputObj | Export-Csv $exportLocation -Append -NoTypeInformation
}
Leave A Comment?