<# ---------------------------------------------------------------------------- # Version: # Created by: # Created on: # Updated on: # Script Function: ---------------------------------------------------------------------------- #> <# edit below this line! #> $Inventory = New-Object System.Collections.ArrayList ############## Provide path where the servers.txt is present ################## $AllComputers = "C:\users\bharalid\desktop\servers.txt" $AllComputersNames = Get-Content $AllComputers Foreach ($ComputerName in $AllComputersNames) { $ComputerName $Connection = Test-Connection $ComputerName -Count 1 -Quiet $ComputerInfo = New-Object System.Object $ComputerOS = Get-ADComputer $ComputerName -Properties OperatingSystem,OperatingSystemServicePack $ComputerInfoOperatingSystem = $ComputerOS.OperatingSystem $ComputerInfoOperatingSystemServicePack = $ComputerOS.OperatingSystemServicePack $ComputerInfo | Add-Member -MemberType NoteProperty -Name "Name" -Value "$ComputerName" -Force $ComputerInfo | Add-Member -MemberType NoteProperty -Name "OperatingSystem" -Value $ComputerInfoOperatingSystem $ComputerInfo | Add-Member -MemberType NoteProperty -Name "ServicePack" -Value $ComputerInfoOperatingSystemServicePack if ($Connection -eq "True"){ $lastpatch = Get-WmiObject -ComputerName $ComputerName Win32_Quickfixengineering | select @{Name="InstalledOn";Expression={$_.InstalledOn -as [datetime]}} | Sort-Object -Property Installedon | select-object -property installedon -last 1 $OSInstalledDate = ([WMI] "").ConvertToDateTime((Get-WmiObject Win32_OperatingSystem -ComputerName $ComputerName).InstallDate) $Computeruptime = ([WMI] "").ConvertToDateTime((Get-WmiObject win32_operatingsystem -ComputerName $ComputerName).lastbootuptime) $ComputerInfo | Add-Member -MemberType NoteProperty -Name "LastBootTime" -Value "$Computeruptime"-Force $ComputerInfo | Add-Member -MemberType NoteProperty -Name "LastPatchInstalled" -Value "$lastpatchInstalled" -Force $ComputerInfo | Add-Member -MemberType NoteProperty -Name "OriginalInstallDate" -Value "$OSInstalledDate" -Force } $Inventory.Add($ComputerInfo) | Out-Null $ComputerHW = "" $ComputerCPU = "" $ComputerDisks = "" $ComputerSerial = "" $ComputerGraphics = "" $ComputerSoundDevices = "" } ################## Provide path for the output #################### $Inventory | Export-Csv C:\users\bharalid\desktop\Inventory.csv