本文整理汇总了C#中PowerShell.AddArgument方法的典型用法代码示例。如果您正苦于以下问题:C# PowerShell.AddArgument方法的具体用法?C# PowerShell.AddArgument怎么用?C# PowerShell.AddArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PowerShell
的用法示例。
在下文中一共展示了PowerShell.AddArgument方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AttachPipeline
private void AttachPipeline(PowerShell ps)
{
foreach (string cmd in pipeLine)
{
if (cmd.Length > 0 && cmd[0] == '$')
{
ps.AddScript(cmd);
}
else
{
string[] cmdOpts = cmd.Split(' ');
string cmdName = cmdOpts[0];
ps.AddCommand(cmdName);
string opts = string.Empty;
bool skip = false;
for (int i = 1; i < cmdOpts.Length; i++)
{
if (skip)
{
skip = false;
continue;
}
if (cmdOpts[i].IndexOf("-") != 0)
{
ps.AddArgument(cmdOpts[i]);
}
else
{
if (i + 1 < cmdOpts.Length && cmdOpts[i + 1].IndexOf("-") != 0)
{
ps.AddParameter(cmdOpts[i].Substring(1), cmdOpts[i + 1]);
skip = true;
}
else
{
ps.AddParameter(cmdOpts[i].Substring(1));
skip = false;
}
}
}
//add storage context for azure storage cmdlet
//It make sure all the storage cmdlet in pipeline use the same storage context
if (cmdName.ToLower().IndexOf("-azurestorage") != -1)
{
AddCommonParameters(ps);
}
}
}
}
示例2: RunScript
private async Task<bool> RunScript(string path)
{
PowerShellInstance = PowerShell.Create();
PowerShellInstance.AddScript(LoadScript(path));
PowerShellInstance.AddArgument(CredentialHelper.GetFormRegistery(CredentialHelper.SourceRepoUserName));
PowerShellInstance.AddArgument(CredentialHelper.GetFormRegistery(CredentialHelper.SourceRepoPassword));
PowerShellInstance.AddArgument(CredentialHelper.GetFormRegistery(CredentialHelper.TargetRepoUserName));
PowerShellInstance.AddArgument(CredentialHelper.GetFormRegistery(CredentialHelper.TargetRepoPassword));
PSDataCollection<PSObject> outputCollection = new PSDataCollection<PSObject>();
outputCollection.DataAdded += outputCollection_DataAdded;
PowerShellInstance.Streams.Error.DataAdded += Error_DataAdded;
IAsyncResult result = PowerShellInstance.BeginInvoke<PSObject,PSObject>(null, outputCollection);
while (result.IsCompleted == false)
{
await Task.Delay(100);
}
return PowerShellInstance.HadErrors;
}