Amend and run the following script to collect hardware information based on computers configured within an OU:
# Before Running the following is required:
# Directory path C:\temp\inventory must exist or the script needs to be altered to the path of your liking
# LDAP path to the container(s) in AD where the computers you'd like to inventory reside need to be updated in the script
# RPC service has to be running
# Portion of script where it gathers computer names from Active Directory to inventory
cls
Write-Host "Scanning Active Directory for Computer Names....." -ForegroundColor Green
# Place the LDAP path to the container in AD that holds your computers.Script will not work until your info is added.
$1 = [ADSI]"LDAP://OU=Computers,OU=IT,HelpDesk,DC=MyDomain,DC=COM"
foreach ($child in $1.psbase.Children) {
if ($child.ObjectCategory -like '*computer*') { Echo $child.Name >> C:\temp\inventory\systemsDT_$((Get-Date).ToString('MM-dd-yyyy')).txt}
}
# Place the LDAP path to the container in AD that holds your computers.Script will not work until your info is added.
# If you have more than two containers just copy the following and change the $2 to $3.
$2 = [ADSI]"LDAP://OU=Computers,OU=IT,PCTech,DC=MyDomain,DC=COM"
foreach ($child in $2.psbase.Children) {
if ($child.ObjectCategory -like '*computer*') { Echo $child.Name >> C:\temp\inventory\systemsDT_$((Get-Date).ToString('MM-dd-yyyy')).txt }
}
# Portion of script where gathered computer names are inventoried
If (Test-Path C:\temp\inventory\systemsDT_$((Get-Date).ToString('MM-dd-yyyy')).txt)
{
Function RunBody
{
gwmi Win32_ComputerSystem -Comp $entry | Export-CSV C:\temp\inventory\GeneralHW_DT_$((Get-Date).ToString('MM-dd-yyyy')).csv -append -force -NoTypeInformation
gwmi Win32_OperatingSystem -Comp $entry | Export-CSV C:\temp\inventory\OS_DT_$((Get-Date).ToString('MM-dd-yyyy')).csv -append -force -NoTypeInformation
gwmi Win32_BIOS -Comp $entry | Export-CSV C:\temp\inventory\BIOS_DT_$((Get-Date).ToString('MM-dd-yyyy')).csv -append -force -NoTypeInformation
gwmi Win32_Processor -Comp $entry | Export-CSV C:\temp\inventory\Processor_DT_$((Get-Date).ToString('MM-dd-yyyy')).csv -append -force -NoTypeInformation
gwmi Win32_LogicalDisk -filter "DriveType = 3" -Comp $entry | Export-CSV C:\temp\inventory\Disk_DT_$((Get-Date).ToString('MM-dd-yyyy')).csv -append -force -NoTypeInformation
gwmi Win32_NetworkAdapterConfiguration -Comp $entry |` where{$_.IPEnabled -eq "True"} | Export-CSV C:\temp\inventory\Nic_DT_$((Get-Date).ToString('MM-dd-yyyy')).csv -append -force -NoTypeInformation
Get-Service remoteregistry -ComputerName $entry | stop-service
}
CLS
$computers = get-content C:\temp\inventory\systemsDT_$((Get-Date).ToString('MM-dd-yyyy')).txt
ForEach ($entry in $computers){
if (Test-Connection -count 1 -computer $entry -quiet){
echo $entry >> C:\temp\inventory\onlineHardwareInvtoryDT_$((Get-Date).ToString('MM-dd-yyyy')).txt
# "Get-Service remoteregistry -ComputerName $entry | start-service" Starts remote registry. Some systems require this to be turned on to avoid RPC errors.
# It is turned off after Inventory is complete. If you keep remote registry on all the time please comment out the Stoping of the remote service.
Get-Service remoteregistry -ComputerName $entry | start-service
Write-Host "Inventorying system" $entry "....." -ForegroundColor Green
RunBody $entry}
Else
{
Write-Host "System" $entry "is offline. Updated offline log. " -ForegroundColor Red
echo $entry >> C:\temp\inventory\offlineHardwareInvtoryDT_$((Get-Date).ToString('MM-dd-yyyy')).txt
}
}
}
Else
{
CLS
Write-Host "systemsDT_$((Get-Date).ToString('MM-dd-yyyy')).txt Not found. Data not collected. " -ForegroundColor Red
}
Write-Host "*************************************************" -ForegroundColor Green
Write-Host "* The Hardware reports are complete. *" -ForeGroundColor Green
Write-Host "* You're Welcome! *" -ForegroundColor Green
Write-Host "* Authored by Perry Orr *" -ForegroundColor Green
Write-Host "*************************************************" -ForegroundColor Green
reference - https://gallery.technet.microsoft.com/Powershell-Computer-or-6cb1f0f0#content
Comments
Post a Comment