Skip to content

Instantly share code, notes, and snippets.

@mark05e
Created February 15, 2022 17:41
Show Gist options
  • Save mark05e/c4ee8ba4d50ca90d4c0b4365a239cd98 to your computer and use it in GitHub Desktop.
Save mark05e/c4ee8ba4d50ca90d4c0b4365a239cd98 to your computer and use it in GitHub Desktop.
A quick audit script to run on multiple machines
$ComputersToWorkOn = @("Server11","Server12","Server13","Server14","Server15")
$report = @()
foreach ($computer in $ComputersToWorkOn) {
Write-Host "Working on $computer ..."
$obj = Invoke-Command -ComputerName $computer -ScriptBlock {
# Count services with the name 'Integration Client Service'
$InstalledServices = (Get-Service -DisplayName '*Integration Client Service*').Count
# Count folders on the E drive location -- hope all the servers have ICs installed here
$InstallationFoldersOnDriveE = (Get-ChildItem -Path 'E:\SoftwareInstallation\' -Directory).Count
$ComputerTimezone = ([TimeZoneInfo]::Local | Select Id).Id
$OSVersionDetails = Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object CSName, Caption, BuildNumber, OSArchitecture
# Get powershell version -- because many new commands are not supported on older versions
$PSVersion = $PSversionTable.PSVersion
$obj = New-Object -TypeName PSObject
$obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $OSVersionDetails.CSName
$obj | Add-Member -MemberType NoteProperty -Name ComputerTimezone -Value $ComputerTimezone
$obj | Add-Member -MemberType NoteProperty -Name InstalledServices -Value $InstalledServices
$obj | Add-Member -MemberType NoteProperty -Name InstallationFoldersOnDriveE -Value $InstallationFoldersOnDriveE
$obj | Add-Member -MemberType NoteProperty -Name OSVersionName -Value $OSVersionDetails.Caption
$obj | Add-Member -MemberType NoteProperty -Name OSBuildNumber -Value $OSVersionDetails.BuildNumber
$obj | Add-Member -MemberType NoteProperty -Name OSArchitecture -Value $OSVersionDetails.OSArchitecture
$obj | Add-Member -MemberType NoteProperty -Name PowershellVersion -Value $PSVersion
return $obj
} #invoke-command
# Append the result to our report
$report += $obj
# Sleep 5 seconds
Start-Sleep -s 5
} #foreach
# Display the report on the terminal
$report | Select-Object * -ExcludeProperty PSComputerName, RunspaceId, PSShowComputerName | Format-Table -AutoSize
# Write the report onto a csv
$report | Select-Object * -ExcludeProperty PSComputerName, RunspaceId, PSShowComputerName | Export-Csv -NoTypeInformation C:\temp\__ServerReport.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment