none
Use Parameter Confirm in powershell RRS feed

  • Question

  • Dear all,

    Here I have one question. There is a powershell command which have a Parameter -Confirm, and I want to use this parameter in my C# code like:

                    parameterConfirm.Confirm = true;
                    this.AddParameter(command, "Confirm", parameterConfirm.Confirm); 

    Then use pipeline to invoke this command. I got question here that looks like parameter Confirm's default value is "N" and the command would fail all the time. Is there any way can I input the value before the command is run or can I take some actions to avoid this?

    Thanks very much.

    Friday, January 7, 2011 2:35 AM

Answers

All replies

  • The way your using the confirm parameter your telling the cmdlet that it should get user confirmation before continuing is this what your want it to do ? Generally if your using Managed code you want to disable the confirmation in the cmdlet so it will execute without user intervention in this case you need to set the confirm parameter to false eg

    cmd.Parameters.Add("Confirm", false);
    
    
    

    Cheers
    Glen

    Friday, January 7, 2011 5:00 AM
  • Thanks for your replay, I want to use parameter confirm, but I just don't know how to give the cmdlet that it should get user confirmation before the command running. Can you give me a help about this?

    Thanks so much.

    Friday, January 7, 2011 5:45 AM
  • The confirm parameter is a mandatory parameter for the cmdlet so you must specify it as a parameter or your code will fail. Because the cmdlet from within Managed code if you want user confirmation why don't you implement your own confirmation and just set it false. Within Powershell you can adjust the confirmpreferance http://blogs.msdn.com/b/powershell/archive/2006/12/15/confirmpreference.aspx.

    If you trying to do input processing this may help http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/abc255ff-cee0-4941-a88c-c095f2110506

    Cheers
    Glen

    • Marked as answer by 络绎 Friday, January 7, 2011 9:08 AM
    Friday, January 7, 2011 6:34 AM
  • Got it. I would watch the page. Thanks for your great replay.
    Friday, January 7, 2011 7:04 AM