locked
Remote WMIC "invalid verb switch", but only when using variables RRS feed

  • Question

  • I'm trying to run a batch script to reset the bitlocker recovery key on a remote machine. Below is what I have so far, but every time i run it, I get "invalid verb switch" on each command.

    @ECHO OFF
    SET /P coname=Please enter the computer name:
    ECHO "resetting bitlocker for %coname%"
    PAUSE
    WMIC /node:"%coname%" process call create “cmd.exe /c manage-bde -protectors -disable %systemdrive%"
    WMIC /node:"%coname%" process call create “cmd.exe /c manage-bde -protectors -delete %systemdrive% -type RecoveryPassword"
    WMIC /node:"%coname%" process call create “cmd.exe /c manage-bde -protectors -add %systemdrive% -RecoveryPassword"
    WMIC /node:"%coname%" process call create “cmd.exe /c manage-bde -protectors -adbackup %systemdrive% -ID KeyProtectorID"
    WMIC /node:"%coname%" process call create “cmd.exe /c manage-bde -protectors -enable %systemdrive%"
    :End

    If I enter the commands one at a time and put the computer name directly in each line instead of a variable, it works. See example below:

    WMIC /node:"MYCOMPUTER" process call create “cmd.exe /c manage-bde -protectors -disable %systemdrive%"

    Any ideas what I'm doing wrong? 


    • Edited by FFwarriorz Tuesday, May 8, 2018 2:14 PM subject change
    • Moved by Bill_Stewart Friday, July 27, 2018 6:45 PM Abandoned
    Friday, May 4, 2018 10:58 PM

All replies

  • Remove the quotes.


    \_(ツ)_/

    Tuesday, May 8, 2018 2:46 PM
  • I tried without quotes but then it gives me invalid global switch. What's weird is if I type the computer name in directly, with quotes, it works fine.

    Our computer names sometimes have a "-" in them. If that's the case, won't I need to use quotes?

    Tuesday, May 8, 2018 3:37 PM
  • You need to do the following before using SET/P

    setlocal enableDelayedExpansion



    \_(ツ)_/

    Tuesday, May 8, 2018 3:59 PM
  • Ok so I just tried that and it gave me "Invalid Global Switch". Same as without quotes with a variable. Still works if I don't use a variable at all. Below is the modified script. I used this link for reference on what syntax to use... https://ss64.com/nt/delayedexpansion.html 

    @ECHO OFF
    setlocal enableDelayedExpansion
    SET /P coname=Please enter the computer name:
    ECHO "resetting bitlocker for !coname!"
    PAUSE
    WMIC /node:!coname! process call create “cmd.exe /c manage-bde -protectors -disable %systemdrive%"
    WMIC /node:!coname! process call create “cmd.exe /c manage-bde -protectors -delete %systemdrive% -type RecoveryPassword"
    WMIC /node:!coname! process call create “cmd.exe /c manage-bde -protectors -add %systemdrive% -RecoveryPassword"
    WMIC /node:!coname! process call create “cmd.exe /c manage-bde -protectors -adbackup %systemdrive% -ID KeyProtectorID"
    WMIC /node:!coname! process call create “cmd.exe /c manage-bde -protectors -enable %systemdrive%"
    pause
    :End
    

    Tuesday, May 8, 2018 4:46 PM
  • I still have no issues with using it either way.

    SET/P is very flakey and behaves differently on different OS versions.


    \_(ツ)_/

    Tuesday, May 8, 2018 5:11 PM