HOWTO split domain\user into two variables (in batch file)

I got input in a batch file in the following format “domain.com\Username”

And I wanted to have two variables:

  • Domain name
  • User name

So i used the variable edit/replace and created the following script which i think will save you 30 min:

@echo off
SET _test=davidovitz.org\infraadmin
set _Username=%_test:*\=%
call set _Domain=%%_test:\%_Username%=%%

echo [%_test%]
echo [%_Username%]
echo [%_Domain%]

HOWTO split domain\user into two variables (in batch file) HOWTO split domain\user into two variables (in batch file) Reviewed by Ran Davidovitz on 2:07 PM Rating: 5

No comments:

Powered by Blogger.