2016-10-03 16 views
1

私はこのコマンドをC#アプリケーション(リストのFirefox拡張機能)内で実行しようとしています。私は、コードを考え出しMSDNのドキュメントからC#でPowerShellコマンドラインを実行

Get-ChildItem -Path $env:USERPROFILE"\AppData\Roaming\Mozilla\Firefox\Profiles\*\extensions.json" | Get-Content 

は(PSラインがない場合)しかし、「結果」はnullある

PowerShell ps = PowerShell.Create(); 
ps.AddCommand("Get-ChildItem"); 
ps.AddParameter("Path", "\"$env:USERPROFILE\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\*\\extensions.json\""); 
ps.AddCommand("Get-Content"); 
Collection<PSObject> results = ps.Invoke(); 

のようなもののように見えるはずです。私はSOに関するいくつかの同様の質問を見つけましたが、実際にこれに答えるために使用できるものは何もありません。誰も私のコードを修正する方法を知っていますか?

答えて

1

PowerShell.Createを使用する代わりに、RunspaceInvoke.Invokeを使用し、完全なコマンドをパラメータとして使用して、結果を得ることができます。希望する:

using (RunspaceInvoke invoke = new RunspaceInvoke()) 
{ 
    Collection<PSObject>result = invoke.Invoke("Get-ChildItem -Path $env:USERPROFILE\"\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\*\\extensions.json\" | Get-Content"); 
} 
関連する問題