Script/Tool that 'Gets all the Windows config data...'
Anyone know of a script/utility that essentially "gets all the conifg data"? As if you were building a CMDB from scratch, and had to populate with data you queried from each computer using all the available WMI classes?
I had a script I had used in the past that I wrote that does this but it's not very efficient. Takes forever to run because it does all its WMI queries from a remote location, and it only does one class at a time (which is needed so it can write one CSV file per class). Ideally would like it to create an Excel spreadsheet with one tab/sheet per WMI class.
Import-Module ActiveDirectory
$devices = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name
$classes = Get-WmiObject -List | Select-Object -ExpandProperty Name
$totalClasses = $classes.Count
$currentClassIndex = 0
foreach ($class in $classes) {
$currentClassIndex++
Write-Host "Processing WMI class $class ($currentClassIndex of $totalClasses)" -ForegroundColor Cyan
$csvPath = "C:\Temp\WMI\WMI_Results_$($class).csv"
$headerWritten = $false
$totalDevices = $devices.Count
$currentDeviceIndex = 0
foreach ($device in $devices) {
$currentDeviceIndex++
Write-Host "Querying $device ($currentDeviceIndex of $totalDevices) for class $class" -ForegroundColor Yellow
try {
$object = Get-WmiObject -Class $class -ComputerName $device -ErrorAction Stop
$properties = $object | Get-Member -MemberType Properties | Select-Object -ExpandProperty Name
foreach ($instance in $object) {
$result = [PSCustomObject]@{ComputerName = $device}
foreach ($property in $properties) {
$result | Add-Member -MemberType NoteProperty -Name $property -Value $instance.$property -Force
}
if (-not $headerWritten) {
$result | Export-Csv -Path $csvPath -NoTypeInformation -Append
$headerWritten = $true
} else {
$result | Export-Csv -Path $csvPath -NoTypeInformation -Append -Force
}
}
} catch {
Write-Host "Failed to query WMI class $class on $device" -ForegroundColor Red
}
}
Write-Host "WMI query results for class $class have been exported to $csvPath" -ForegroundColor Green
}