本文整理汇总了C#中PowerShell.AddParameter方法的典型用法代码示例。如果您正苦于以下问题:C# PowerShell.AddParameter方法的具体用法?C# PowerShell.AddParameter怎么用?C# PowerShell.AddParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PowerShell
的用法示例。
在下文中一共展示了PowerShell.AddParameter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCommonParameters
/// <summary>
/// Add the common parameters
/// -Context ...
/// </summary>
internal void AddCommonParameters(PowerShell ps)
{
if (UseContextParam && AgentContext != null)
{
ps.AddParameter(ContextParameterName, AgentContext);
}
}
示例2: InvokeStoragePowerShell
private bool InvokeStoragePowerShell(PowerShell ps, object context = null)
{
if (context == null)
{
AddCommonParameters(ps);
}
else
{
ps.AddParameter(ContextParameterName, context);
}
Test.Info(CmdletLogFormat, MethodBase.GetCurrentMethod().Name, GetCommandLine(ps));
//TODO We should add a time out for this invoke. Bad news, powershell don't support buildin time out for invoking.
try
{
ParseCollection(ps.Invoke());
}
catch (Exception e)
{
Test.Info(e.Message);
}
ParseErrorMessages(ps);
return !ps.HadErrors;
}
示例3: 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);
}
}
}
}