更新。cmdlet
我在 Visual Studio 2010 中使用 C#/.Net 4.0创建了一个 PowerShell 3.0 。它工作正常。但这cmdlet
需要一段时间,我想添加一个进度条。
MSDN 文档在 WriteProgressCommand 上含糊不清。这是链接: http: //msdn.microsoft.com/en-us/library/microsoft.powershell.commands.writeprogresscommand.completed (v=vs.85).aspx
下面的代码显示了我想要做什么。基本上在ProcessRecord()
. 然后每秒更新进度条。不知道如何显示进度条。帮助?
[System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.Get, "StatusBar")]
public class GetStatusBarCommand : System.Management.Automation.PSCmdlet
{
/// <summary>
/// Provides a record-by-record processing functionality for the cmdlet.
/// </summary>
protected override void ProcessRecord()
{
WriteProgressCommand progress = new WriteProgressCommand();
for (int i = 0; i < 60; i++)
{
System.Threading.Thread.Sleep(1000);
progress.PercentComplete = i;
}
progress.Completed = true;
this.WriteObject("Done.");
return;
}
}
// Commented out thanks to Graimer's answer
// [System.Management.Automation.CmdletAttribute("Write", "Progress")]
// public sealed class WriteProgressCommand : System.Management.Automation.PSCmdlet { }