none
Enable-MSDSMAutomaticClaim can't run this silently? RRS feed

  • Question

  • Hi,

    I am trying to run the following command however, it always asks for a confirmation, but I am trying to run this in a script for automated configuration. is there any way i can run this "silently" which will accept the Yes or All confirmation?

    Enable-MSDSMAutomaticClaim –BusType iSCSI

    thanks

    Steve

    Thursday, August 14, 2014 7:06 AM

Answers

  • Hi Steve,

    first: You could do it in two lines:

    $ConfirmPreference = "None"
    Enable-MSDSMAutomaticClaim -BusType iSCSI

    If you want to put several separate commands into the same line (which may sometimes be the case when typing into the console), then you can separate them with a Semicolon like this:

    $ConfirmPreference = "None"; Enable-MSDSMAutomaticClaim -BusType iSCSI

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Milkientia Thursday, August 14, 2014 8:50 AM
    • Unmarked as answer by Milkientia Friday, August 15, 2014 7:10 AM
    • Marked as answer by Milkientia Friday, August 15, 2014 2:40 PM
    Thursday, August 14, 2014 7:57 AM
  • The problem is scope.

    $global:ConfirmPreference = "None"
    Enable-MSDSMAutomaticClaim -BusType iSCSI


    ¯\_(ツ)_/¯

    • Marked as answer by Milkientia Friday, August 15, 2014 2:40 PM
    Friday, August 15, 2014 9:26 AM

All replies

  • Hi Steve,

    if the cmdlet has a "-Confirm" Parameter, yiou can set it to false like this:

    -Confirm:$false

    even if it does not, you can set your $ConfirmPreference to "none":

    $ConfirmPreference = "None"

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Thursday, August 14, 2014 7:16 AM
  • hi,

    it does not have a -Confirm parameter, however how would my full line look like using your $ConfirmPreference = "None" setting..... i dont quite understand how that fits in (sorry, still new to powershell)

    thanks

    Steve

    Thursday, August 14, 2014 7:51 AM
  • Hi Steve,

    first: You could do it in two lines:

    $ConfirmPreference = "None"
    Enable-MSDSMAutomaticClaim -BusType iSCSI

    If you want to put several separate commands into the same line (which may sometimes be the case when typing into the console), then you can separate them with a Semicolon like this:

    $ConfirmPreference = "None"; Enable-MSDSMAutomaticClaim -BusType iSCSI

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Milkientia Thursday, August 14, 2014 8:50 AM
    • Unmarked as answer by Milkientia Friday, August 15, 2014 7:10 AM
    • Marked as answer by Milkientia Friday, August 15, 2014 2:40 PM
    Thursday, August 14, 2014 7:57 AM
  • that's great, seems to have worked perfectly. I didnt realise that $ConfirmPreference was a build in PowerShell variable :)

    thanks for that

    Steve

    Thursday, August 14, 2014 8:16 AM
  • Hi,

    This appeared to work when I ran it as a command (both approaches whether it be separate lines or all in one) however, when i ran it as part of a script it still prompted me for an answer. I am therefore rather confused as to why it would work as a command but not in a script. You would have thought all commands which require an answer would include a -Confirm parameter but this appears to not have one.

    Steve

    Friday, August 15, 2014 7:13 AM
  • The problem is scope.

    $global:ConfirmPreference = "None"
    Enable-MSDSMAutomaticClaim -BusType iSCSI


    ¯\_(ツ)_/¯

    • Marked as answer by Milkientia Friday, August 15, 2014 2:40 PM
    Friday, August 15, 2014 9:26 AM
  • I havent tried this way yet, but even though i place it directly before the command i want to run, you're saying that doesnt make a difference?

    thanks

    Steve

    Friday, August 15, 2014 10:25 AM
  • I havent tried this way yet, but even though i place it directly before the command i want to run, you're saying that doesnt make a difference?

    thanks

    Steve

    There is no difference.  The semicolon is the same as a new line when PowerShell parses it.

    With this command you can more easily do this:

    Enable-MSDSMAutomaticClaim -BusType iSCSI -Confirm:$false

    See: http://technet.microsoft.com/library/hh847884.aspx


    ¯\_(ツ)_/¯

    Friday, August 15, 2014 10:49 AM
  • sorry, i meant what is the difference between setting the variable before the command, compared to using the global prefix? why wouldn't my other way of setting it work?

    I haven't confirmed yet whether this solves it or not, the script runs as part of an automated server build so it will take a while to test it.

    thanks

    Steve

    Friday, August 15, 2014 11:12 AM
  • Hi,

    This appeared to work when I ran it as a command (both approaches whether it be separate lines or all in one) however, when i ran it as part of a script it still prompted me for an answer. I am therefore rather confused as to why it would work as a command but not in a script. You would have thought all commands which require an answer would include a -Confirm parameter but this appears to not have one.

    Steve

    It appears the documentation is a little sloppy.  

    According to this: 

    http://chinnychukwudozie.com/2013/11/11/configuring-multipath-io-with-multiple-iscsi-connections-using-powershell/

    That's actually a function, not a cmdlet.  And it appears they've not provided a parameter for Confirm.


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Friday, August 15, 2014 11:16 AM
    Moderator
  • I have just tested this and it seems to have worked great, i dont understand the difference between setting the variable before running the command and setting the variable using the global prefix before running the command. I would have thought they would both do the same thing but it appears not so.

    thanks for the help, all sorted.

    Steve

    Friday, August 15, 2014 2:40 PM
  • I have just tested this and it seems to have worked great, i dont understand the difference between setting the variable before running the command and setting the variable using the global prefix before running the command. I would have thought they would both do the same thing but it appears not so.

    thanks for the help, all sorted.

    Steve

    You should take a bit to study how "scope" works.


    ¯\_(ツ)_/¯

    Friday, August 15, 2014 2:43 PM