0
$features = Start-Process powershell -Verb runAs -ArgumentList "Get-WindowsOptionalFeature –Online" $features
Start-Processからウィンドウコマンドの結果をキャプチャするには?
どうすれば結果を$feature
変数に戻すことができますか?
$features = Start-Process powershell -Verb runAs -ArgumentList "Get-WindowsOptionalFeature –Online" $features
Start-Processからウィンドウコマンドの結果をキャプチャするには?
どうすれば結果を$feature
変数に戻すことができますか?
クイック&汚い回避策:
$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
}
}
'は、Get-WindowsOptionalFeature -Online'を昇格ウィンドウからコマンドを実行します。あなたが取得-WindowsOptionalFeatureコマンドレットの結果を保存するために一時的Clixmlコマンドファイルを使用することができます。 –
[開始プロセスの標準出力とエラーの取り込み]の可能な複製(https://stackoverflow.com/questions/8761888/capturing-standard-out-and-error-with-start-process) –
このリンクに続いて、 'StartInfo.Verb =" runas "'を指定してプロセスを実行する必要があります。 –