PowerShell - Search Server List for all services
- Jon Boyette
- Jan 12, 2022
- 1 min read
Save as a ServerandServiceAccount.ps1 or named, this takes the servers/computers in c:\temp\servers.txt, and makes a C:\temp\ServiveAndServiceAccounts folder that is populated with a csv PER server in the test list, showing ALL services on remote Computer(S)
param (
[string[]]$ServerArray = (Get-Content -Path c:\temp\servers.txt),
[string]$SaveLocation = "C:\Temp\ServiceandServiceAccounts"
)
# Test if folder exists, otherwise create folder
if (-not (Test-Path -Path $SaveLocation)) {
New-Item -ItemType directory -Path $SaveLocation
}
# Main loop of script
Foreach ($Server in $ServerArray ) {
$CurrentLogFile = Join-path -Path $SaveLocation -ChildPath "$Server-Services.csv"
"Retrieving services for $Server"
Get-WmiObject win32_service -ComputerName $Server | select Name,
@{N="Startup Type";E={$_.StartMode}},
@{N="Service Account";E={$_.StartName}},
@{N="System Name";E={$_.Systemname}} |
Sort-Object "Name" | Export-Csv -Path $CurrentLogFile -NoTypeInformation
}
Comments