Calling an Array in PowerShell -


i have string array $exclude want put filter in get-wmiobject cmdlet. have added @ end not work.

how can filter out services listed in array?

$servicestoexclude = "remoteregistry,cpqnicmgmt" $exclude = $servicestoexclude.split(",") $services = get-wmiobject -class win32_service -filter {state != 'running' , startmode = 'auto' , name -ne $exclude}    $result =    foreach ($service in $services.name)      {            get-itemproperty -path "hklm:\system\currentcontrolset\services\$service" |              where-object {$_.start -eq 2 -and $_.delayedautostart -ne 1}|              select-object -property @{label='servicename';expression={$_.pschildname}} |              get-service           }  if ($result.count -gt 0){ $displayname = $result.displayname [string]   $line = "`n-----------------------------------------"  $api.logscriptevent( 'stopped_auto_services.ps1',1234,4,"`nstopped automatic services$line `n$($displayname)") 

filtering array out of list not done on wmi side. instead, should use where-object filter out services name contained in $exclude.

$services = get-wmiobject -class win32_service -filter {state != 'running' , startmode = 'auto'} | where-object {$exclude -notcontains $_.name} 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -