我有以下代碼:寫作PowerShell的C#代碼中直接命令
PowerShell ps = PowerShell.Create();
// Call the PowerShell.AddCommand(string) method, add
// the Get-Process cmdlet to the pipeline. Do
// not include spaces before or after the cmdlet name
// because that will cause the command to fail.
ps.AddCommand("mkdir");
ps.AddArgument("C:\\Users\\me\\Desktop\\test");
不幸的是,當我運行這段代碼,不創建目錄。我想我誤解了這是如何工作的,但理想情況下,我希望我的最終應用程序能夠運行PowerShell命令,然後直接在我的應用程序中獲取輸出。
我做錯了從我的代碼執行一個簡單的powershell命令?
add'ps.Invoke()' –