0
$features = Start-Process powershell -Verb runAs -ArgumentList "Get-WindowsOptionalFeature –Online" $features
如何從Start-Process捕獲Windows命令結果?
如何將結果返回到我的$feature
變量中?
$features = Start-Process powershell -Verb runAs -ArgumentList "Get-WindowsOptionalFeature –Online" $features
如何從Start-Process捕獲Windows命令結果?
如何將結果返回到我的$feature
變量中?
快速&髒解決辦法:你可以用臨時CLIXML文件來存儲獲取-WindowsOptionalFeature cmdlet的結果:
$tempFile = [System.IO.Path]::GetTempFileName()
try
{
Start-Process powershell -Wait -Verb runAs -ArgumentList "-Command Get-WindowsOptionalFeature -Online | Export-Clixml -Path $tempFile"
$features = Import-Clixml -Path $tempFile
# Use $features
}
finally
{
if (Test-Path $tempFile)
{
Remove-Item -Path $tempFile -Force -ErrorAction Ignore
}
}
運行'從提升窗口獲取-WindowsOptionalFeature -Online'。 –
[捕獲標準輸出和錯誤與啓動過程](https://stackoverflow.com/questions/8761888/capturing-standard-out-and-error-with-start-process) –
在此鏈接之後,您'需要指定'StartInfo.Verb =「runas」'來運行升級過程。 –