我正在尝试在我一直在开发的 C# 程序中运行一些 Powershell cmdlet。
我一直尝试运行的 cmdlet 如下:
$cred = New-Object System.Management.Automation.PSCredential (user, (ConvertTo-SecureString pass –ASPlainText –Force));
我在 C# 程序中所做的如下:
string user = textBox1.Text;
string pass = textBox2.Text;
PowerShell ps = PowerShell.Create();
ps.AddCommand("New-Object");
ps.AddArgument("System.Management.Automation.PSCredential ("+user+", (ConvertTo-SecureString "+pass+" –ASPlainText –Force))");
var cred = ps.Invoke();
但是当我这样做时,我收到以下错误提示:
A constructor was not found. Cannot find an appropriate constructor for type System.Management.Automation.PSCredential (user, (ConvertTo-SecureString pass –ASPlainText –Force)).
所以我的问题是,如何从 C# 程序运行此 Powershell cmdlet,并将结果存储在 C# 程序内的变量中?
MM们
慕少森
相关分类