本文整理汇总了C#中PowerShell.BindParameter方法的典型用法代码示例。如果您正苦于以下问题:C# PowerShell.BindParameter方法的具体用法?C# PowerShell.BindParameter怎么用?C# PowerShell.BindParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PowerShell
的用法示例。
在下文中一共展示了PowerShell.BindParameter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCommonParameters
/// <summary>
/// Add the common parameters
/// -Context ...
/// </summary>
internal void AddCommonParameters(PowerShell ps)
{
if (UseContextParam && AgentContext != null)
{
ps.BindParameter(ContextParameterName, AgentContext);
}
}
示例2: InvokeStoragePowerShell
private bool InvokeStoragePowerShell(PowerShell ps, object context = null)
{
if (context == null)
{
AddCommonParameters(ps);
}
else
{
ps.BindParameter(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
/// <summary>
/// Attach some script to the current PowerShell instance
/// Attach Rule :
/// 1. If the script is start with "$", we directly add it to the pipeline
/// 2. If the current script is storage cmdlet, we need to add the current storage context to it.
/// 3. Otherwise, split the script into [CommandName] and many [-Parameter][Value] pairs, attach them using PowerShell command interface(AddParameter/AddCommand/etc)
/// //TODO update the step 3
/// </summary>
/// <param name="ps">PowerShell instance</param>
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.BindParameter(cmdOpts[i].Substring(1), cmdOpts[i + 1]);
skip = true;
}
else
{
ps.BindParameter(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);
}
}
}
}