Skip to content

Instantly share code, notes, and snippets.

@debold
Created September 24, 2020 12:31
Show Gist options
  • Save debold/ffaaa7eb3c78aa18d97ee27efc44bb5f to your computer and use it in GitHub Desktop.
Save debold/ffaaa7eb3c78aa18d97ee27efc44bb5f to your computer and use it in GitHub Desktop.
Collect a quick software inventory from all domain servers
$Servers = Get-ADComputer -Filter { OperatingSystem -like "*server*" -and Enabled -eq $true } -Properties OperatingSystem
$Results = @()
foreach ($Server in $Servers) {
Write-Host $Server.Name -NoNewline
try {
Test-Connection -ComputerName $Server.DnsHostName -Count 1 -ErrorAction Stop | Out-Null
$found = $true
Write-Host "`tfound`t" -NoNewline -ForegroundColor Green
} catch {
$found = $false
Write-Host "`tfailed`t" -NoNewline -ForegroundColor Red
}
if ($found) {
$Software = Get-WmiObject -Query "Select * from Win32_Product" -ComputerName $Server.DnsHostName
foreach ($Product in $Software) {
$Results += New-Object -TypeName PsObject -Property @{
Server = $Server.Name;
Vendor = $Product.Vendor;
Software = $Product.Name;
Version = $Product.Version
}
}
}
Write-Host "done"
}
$Results | Export-Csv -Path .\Software.csv -Delimiter ";" -NoTypeInformation -Encoding Default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment