我想列出所有启动类型设置为自动的服务
我正在使用 PowerShell 5
$path = 'hklm:\SYSTEM\ControlSet001\Services'
$services = get-childitem $path | get-itemproperty -name 'Start'
foreach ($s in $services){
if($s.'Start' -like '2'){
$dn = get-itemproperty $s.'pspath' -name 'DisplayName'
echo $dn
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是大多数条目都在使用这样的东西:
$path = 'hklm:\SYSTEM\ControlSet001\Services'
$services = get-childitem $path | get-itemproperty -name 'Start'
foreach ($s in $services){
if($s.'Start' -like '2'){
$dn = get-itemproperty $s.'pspath' -name 'DisplayName'
echo $dn
}
}
Run Code Online (Sandbox Code Playgroud)
那么如何从中提取字符串呢?
进一步澄清一点,因为@%systemroot%\system32\SearchIndexer.exe,-103显示名称是"Windows Search". 现在的问题是,是PowerShell的能提取字符串"Windows Search"出来的SearchIndexer.exe?以及如何做到这一点?
更新: