$features = Start-Process powershell -Verb runAs -ArgumentList "Get-WindowsOptionalFeature –Online"
$features
如何将结果返回到我的$feature
变量?
答案 0 :(得分:1)
快速&脏解决方法:您可以使用临时clixml文件来存储Get-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
}
}