I'm trying to filter objects that don't contain the string "C: \ Windows"
in their path but the filtering isn't working well with $_.PathName
parameter.
function unquotedPath {
$unquotedPaths = Get-WmiObject -Class Win32_Service | Where-Object {$_.StartMode -eq "Auto" -and $_.PathName -notcontains "C:\WINDOWS\"} | Select-Object -Property Name,DisplayName,PathName,StartMode | Out-String
foreach ($unquotedPath in $unquotedPaths) {
Write-Host $unquotedPath -ForegroundColor Green
}
}