我在powershell中运行以下脚本。 (它保存在temp.ps1文件中)
[String]$ServiceAccountPassword ='Password'
$secpass = ConvertTo-SecureString –String $ServiceAccountPassword –AsPlainText -Force
当我从powershell ISE运行它时,它运行正常。
但是当从c#应用程序调用此脚本时,即
_powerShell = PowerShell.Create();
var sr = new StreamReader(scriptFile);
_powerShell.AddScript(sr.ReadToEnd());
_powerShell.InvocationStateChanged += _powerShell_InvocationStateChanged;
var outputCollection = new PSDataCollection<PSObject>();
outputCollection.DataAdded += outputCollection_DataAdded;
_powerShell.Streams.Error.DataAdded += Error_DataAdded;
IAsyncResult async =_powerShell.BeginInvoke<PSObject, PSObject>(null, outputCollection, null, AsyncInvoke, null);
我正在
无法转换&#39; System.String&#39;到#System ;Management.Automation.SwitchParameter&#39;参数&#39; AsPlainText&#39;。
需要