I would like to know how i could create an array in Power shell V3 to generate a list of software on a local machine with the letter L for running services?
-
1What have you tried? Have you made any attempt on your own, or are you asking for people here to write the whole thing for you? What is the source of this list - where is it stored, what counts as "installed", and what is the distinction between services and software?– alrocCommented Feb 11, 2014 at 15:05
Add a comment
|
1 Answer
I don't know what you call a list of software on a local machine, but the following code creates a list of all Windows services on a machine with a letter "L" for those that are currently running.
$services = @() # create an empty array
$services = Get-Service | ` # get a list of services
foreach {
# project each element in the list to a new object with two properties:
@{
IsRunning = (&{ # "L" if a service is active, i.e. in "Running" status
if ($_.Status -eq "Running") { "L" } else { "" } # or "" otherwise
})
Name = $_.Name # a name of a service
}
}