1

I have a bash script with following:

USERLIST="/tmp/adusers.list.names.only.txt"
cat $USERLIST | while read users
do
num=$[$num+1]
USR=`echo $users | awk '{print $1}'`
STATUS=`winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser $USR -Properties * | select Enabled"'`
echo "$USR : $STATUS"
done

But command not getting user name, instead its showing $USR variable.

winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser $USR -Properties * | select Enabled"'

I tried to double quote like "$VAR" but no use.

1

1 Answer 1

2

It looks like the $USR part in the winexe call is not being translated into the variable because it's inside a single quote (')

Try changing the line

STATUS=`winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser $USR -Properties * | select Enabled"'`

into

STATUS=`winexe -U DC/ID%"PASS" //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser '"$USR"' -Properties * | select Enabled"'`

so as to escape the single-quote, enter a double-quote and thereby insert the variable value.

1
  • yes i tried to escape the single-quote/double quote by above method, but then the script does not proceed further and pause at following . (output) root@linux:/temp# ./test.sh + USERLIST=/tmp/adusers.list.names.only.txt + read users + cat /tmp/adusers.list.names.only.txt + num=1 ++ awk '{print $1}' ++ echo $'user1.local\r' + USR=$'user1.local\r' -Properties * | select Enabled"'ADPASS //10.0.0.1 'powershell.exe -command "import-module activedirectory; Get-ADUser user1.local afterword it does not move further Commented Feb 14, 2017 at 3:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .