Search code examples
windowsbatch-filenetwork-drive

batch script - map network drives by computer name


I am trying to modify a current script that is executed as logon script by domain GPO. I have a special case where if users log into a specific machine on the domain, I need to map different network drives. Otherwise all other computers load the basic drive mappings.

I have tries both of the following without any success:

echo %COMPUTERNAME% | %SYSTEMROOT%\System32\find.exe /i "VMMACHINE" > nul:
if %ERRORLEVEL% EQU 0 goto VMMACHINE-DRIVES

and I have tried

if %COMPUTERNAME% EQU "VMMACHINE" goto VMMACHINE-DRIVES

Can anyone help?


Solution

  • I think you want:

    if "%COMPUTERNAME%" == "VMMACHINE" goto VMMACHINE-DRIVES
    

    Add " to interpret %COMPUTERNAME% as a string and == for string comparison.