Updated. I created a PowerShell 3.0 cmdlet using C#/.Net 4.0 in Visual Studio 2010. It works fine. But the cmdlet takes a while and I want to add a progress bar.
The MSDN documentation is vague on WriteProgressCommand. Here is the link: http://msdn.microsoft.com/en-us/library/microsoft.powershell.commands.writeprogresscommand.completed(v=vs.85).aspx
The code below shows what I want to do. Basically do some processing under ProcessRecord(). Then every second update the progress bar. Not sure how to display the progress bar. Help?
[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 { }