Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:51:49+00:00 2026-06-15T23:51:49+00:00

Updated. I created a PowerShell 3.0 cmdlet using C#/.Net 4.0 in Visual Studio 2010.

  • 0

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 { }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:51:50+00:00Added an answer on June 15, 2026 at 11:51 pm

    I’ve tested cmdlet developing for 10min now and figured out how the progressbar works. I couldn’t even add that WriteProgressCommand class(but then again I’m a programming noob). What I did get to work though was the following:

    protected override void ProcessRecord()
          {
             ProgressRecord myprogress = new ProgressRecord(1, "Testing", "Progress:");
    
              for (int i = 0; i < 100; i++)
              {
                  myprogress.PercentComplete = i;
                  Thread.Sleep(100);
                  WriteProgress(myprogress);
              }
    
                 WriteObject("Done.");
          }
    

    ProgressRecord stores the progress-definition and you call a WriteProgress command to update the shell(powershell window) with the newly updated progressdata. “1” in the constructor is just an id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using acts_as_audited gem in Ruby it works fine. When I created, updated or
I have two IIS websites, namely accounts.example.com that was created in Visual Studio 2010
Trying to execute a Powershell cmdlet from a MVC 3 Controller using impersonation but
I want to access an array that is created and updated in the native
I have a JSON array like this: { forum:[ { id:1, created:2010-03-19 , updated:2010-03-19
I've created an Azure Worker Role running node.js using the Windows Azure PowerShell .
I want to create a continuous build integration system for .NET using just Windows
I have MyModel that, whenever it is created or updated, I want to insert
I updated my code with string dates created with new Date and added back
I Have XML similar to this(omitted parts for brevity): <uformrecord> <state>Submitted</state> <created>2012-06-19T11:31:54</created> <updated>2012-06-19T11:32:13</updated> <id>53225sas3c1-d727-42cd-93a6-97cd778e5ee9</id>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.