I am working on a PowerShell script that would list the “Name” and “State” of all the websites located on a specific server. I use the command below which works as expected.
Invoke-Command -ComputerName “WebServer01” { Get-WebSite | Select-Object “State”, “Name” }
OUTPUT
state name
Started website01
Stopped website02
. . .
Started website11
What I would like to do is have a number assigned to each line with a website. This way I could select a certain website by number then use this to perform an action (e.g. start, stop, restart)
OUTPUT
state name
------ ------
1 Started website01
2 Stopped website02
. . .
11 Started website11
I have used the command below to get the number of lines of output, but I am not sure how to use it, or even if this is the right approach to get the number of output lines.
$Test = Invoke-Command -ComputerName “$cmpName” { Get-WebSite | Select-Object “State”, “Name” | Measure-Object }
$Test.Count
OUTPUT
11
Any help would be greatly appreciated.