Well, all you want to know to start with is in the built-in help files
# Get parameters, examples, full and Online help for a cmdlet or function
(Get-Command -Name Get-Content).Parameters
Get-help -Name Get-Content -Examples
Get-help -Name Get-Content -Full
Get-help -Name Get-Content -Online
Get-Help about_*
Get-Help about_For
Get-Help about_ForEach*
Get-Help about_Operators
# All Help topics locations
explorer "$pshome\$($Host.CurrentCulture.Name)"
Tyr to avoid the use of contains on simple strings (though you can do it), as a rule, as its use case is to look at a collection or stuff. Use -match or Select-String instead. See the above help on operators.
So, based on what you are after. How about this approach.
($account = 'LocalSystem')
Get-WmiObject Win32_service `
| Where {$_.StartName -eq $account -and $_.Name -notmatch '.*SQL.*|ReportServer'} `
| Select Name,State,StartMode,StartName `
| Format-Table -AutoSize
Name State StartMode StartName
---- ----- --------- ---------
AdobeARMservice Running Auto LocalSystem
AESMService Running Auto LocalSystem
Appinfo Running Manual LocalSystem
AppMgmt Stopped Manual LocalSystem
...
($account = 'LocalSystem')
Get-WmiObject Win32_service `
| Where {$_.StartName -eq $account -and $_.Name -match '.*SQL.*|ReportServer'} `
| Select Name,State,StartMode,StartName `
| Format-Table -AutoSize
Name State StartMode StartName
---- ----- --------- ---------
SQLWriter Running Auto LocalSystem
Lastly, depending on you PoSH version; never use Write-Host, except for outputting colorized text to the screen or other custom formatting needs. Output to the screen is the default.
So, this…
write-host $service
and this…
$service
and this…
“$service”
and this…
($service)
…will do exactly the same thing, output to the screen.
The Write-Host specifically clears the buffer so, anything in that varible is gone. So, no pipeline when you use it.
See
Write-Host Considered Harmful - by PowerShell founder Jeffrey Snover
‘Write-Host Considered Harmful | Jeffrey Snover's blog’
However, now, in PoSHv5 Jeffrey Snover now says…
With PowerShell v5 Write-Host no longer “kills puppies”. data is captured into info stream
‘Write-Information (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn’