1 回答

TA貢獻1936條經(jīng)驗 獲得超7個贊
問題似乎出在您的腳本上。設置ExecutionPolicy中游不會做任何事情,并且您沒有編寫函數(shù),因此添加$PSBoundParameters也不會做任何事情。這是一個應該有效的示例(我將來會指定 PS 版本。由于鍵盤過濾,我知道您使用的是 v5.1/win10)
$collection = [System.Collections.Generic.List[string]]::new()
foreach ($key in (Get-CimInstance -Namespace 'root\standardcimv2\embedded' -ClassName WEKF_PredefinedKey)) {
if (-not $key.Enabled) {
$collection.Add($key.ToString())
}
}
return $collection
(簡化)
@(Get-CimInstance -Namespace root\standardcimv2\embedded -ClassName WEKF_PredefinedKey).
Where{-not $_.Enabled}.
ForEach('ToString')
例子:
using (PowerShell ps = PowerShell.Create())
{
string script = @"Import-Module -Name C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1 -ErrorAction Stop; @(Get-WmiObject -Namespace root\standardcimv2\embedded -Class WEKF_PredefinedKey -ErrorAction Stop).Where{-not $_.Enabled}.ForEach('ToString')";
ps.AddScript(script);
var result = ps.Invoke();
}
- 1 回答
- 0 關注
- 585 瀏覽
添加回答
舉報