
close
close
Chance to win $250 in Petri 2023 Audience Survey
In this article, I’ll show you how to identify services that have IIS installed. I’m using IIS for the sake of my demonstrations, but you could apply this article to any product or service. One of the first questions to ask is what is an authoritative indicator? There could be more than one, but once you know what to look for, then it’s a simple matter of finding the corresponding PowerShell commands to retrieve that information.
In the case of IIS, the first thing I would check is if the Web-Server feature is installed using Get-WindowsFeature.
Get-WindowsFeature -Name Web* -ComputerName chi-web02
I picked a server that I already knew had this feature installed.
Listing web features (Image Credit: Jeff Hicks)
Get-WindowsFeature -Name Web* -ComputerName chi-web02 | where installed
Listing only installed web features (Image Credit: Jeff Hicks)
get-content c:\work\servers.txt | where { Get-WindowsFeature -Name Web-Server -ComputerName $_ | Where Installed}
This gets a little tricky because I have a nested Where-Object statement. If the computer does not have the Web-Server feature installed, then there will be nothing in the pipeline. The only names that come through will be those that have the feature installed, which in my list is three servers.
Filtering a list of computers where Web-Server is installed (Image Credit:Jeff Hicks)
Using Get-Service to identify an installed feature (Image Credit: Jeff Hicks)
get-content C:\work\servers.txt | where {Get-Service w3svc -ComputerName $_}
By using this command, you’ll also get a lot of errors because Get-Service throws an exception if it can’t find the service. The easy solution is to temporarily turn errors off because we really don’t care about those computers.
get-content C:\work\servers.txt | where {Get-Service w3svc -ComputerName $_ -ErrorAction SilentlyContinue}
Filter a text list with Get-Service (Image Credit: Jeff Hicks)
get-content C:\work\servers.txt | foreach {Get-Service w3svc -ComputerName $_ -ErrorAction SilentlyContinue} | Select Machinename,Name,Status
In this case, I want to get the actual service.
Getting service details (Image Credit: Jeff Hicks)
get-ciminstance -class Win32_service -filter "name='w3svc'" -computername (get-content c:\work\servers.txt)
Filtering with Get-CimInstance (Image Credit: Jeff Hicks)
get-content c:\work\servers.txt | where { get-process DNS -ComputerName $_ -ErrorAction SilentlyContinue} get-ciminstance -ClassName win32_process -filter "name='dns.exe'" -ComputerName (get-content c:\work\servers.txt)
Multiple ways to list process information (Image Credit: Jeff Hicks)
Getting process start information (Image Credit: Jeff Hicks)
Get-CimInstance -ClassName win32_process -filter "Commandline like '%iissvcs'" -ComputerName (get-content c:\work\servers.txt) | select ProcessID,Name,Commandline,PSComputername
And sure enough I get the same servers:
Finding the IIS process (Image Credit: Jeff Hicks)
More in PowerShell
Most popular on petri