PowerShell Basics: Listing the number of services each user has per server

Infrastructure audits can be fun right? While they can be tedious at best, most IT Professionals are prepared via the use of Operations Management Suite or other 3rd party software that can literally produce a report in minutes (depending on infrastructure size of course!)

What about if you don't have access to these tools?

Fear not as there are many PowerShell scripts that can reliably provide the required information needed. However, some assembly of the required report may be required.

One common ask most IT Professionals receive when audited is to provide a listing of services used by each user has per server. This inquiry is common when an audit is required to prove users have been assigned appropriate services per server.  Simply utilize the following PowerShell script to automate this function and skip the manual route:

$server_names = Get-Content "C:\Servers_list.txt"
Foreach ($server in $server_names){
Get-WmiObject Win32_service | Where-Object {$_.state -eq "Running"} | Group-Object -Property StartName | Format-Table $server,Name, Count -auto >> c:\ServiceAccounts.txt


Comments (1)
  1. sSan says:

    this is a very interesting topic. I think:
    ..continuing this audit analysis of list of running services, one may want to investigate further the “installed roles and features” upon finding those services.
    CANITPRO can use this command to find out the installed Windows features)PS:>
    Get-WindowsFeature | Where-Object{$_.InstallState -eq “Installed”}
    This commands has been tested on a Windows (Server)computer with PowerShell 4.0.

    To express more about the power of PowerShell:
    I remember I was looking for a native code, pure PowerShell to Set a Windows Service Startup Type. Someone helped me learn about Get-WmiObject. Now with the power of PowerShell 4.0 (thanks to engineers) I can set a Windows service (i.e. Windows update) startup type if needed for auditing purposes:
    Get-Service “Windows Update” | Set-Service -StartupType Manual

    After audit, DSC resources can help to automate and monitor an environment (Windows, or Linux) configuration settings to comply.

Comments are closed.

Skip to main content