Você pode usar um loop para / f e colocar o comando net user
canalizado para um findstr usando tokens
e delims
de acordo com o script em lote para analisar a saída e obter o valor do campo User profile
, que está definido para a conta no AD que você executa nesse comando.
Script
@ECHO ON
for /f "tokens=3 delims= " %%a in ('net user <username> /domain ^| findstr /i "profile"') do set profilepath=%%a
echo %profilepath%
Script Notes
This script assumes you will replace
<username>
below with the explicit value of the needed username when run to get theProfile path
from thenet use xxx /domain
command.The caret symbol in front of the pipe symbol ( i.e.
^|
) within the brackets of thefor /f
loop pipes the output of thenet user
command into thefindstr
command so it's there to escape the pipe symbol so at command execution time within the loop it knows that's redirecting one command's output as another commands input otherwise it gets confused so simply escape it.The percent sign has special meaning in batch scripts so when using a
for
loop within a batch script you need to double the percent sign i.e.%%a
of this placeholder to escape it ensuring it's interpreted as a single%
and can pass the variable accordingly within the loop.
Mais recursos
- FOR / F
-
For /?
delims=xxx - specifies a delimiter set. This replaces the default delimiter set of space and tab. tokens=x,y,m-n - specifies which tokens from each line are to be passed to the for body for each iteration. This will cause additional variable names to be allocated. The m-n form is a range, specifying the mth through the nth tokens. If the last character in the tokens= string is an asterisk, then an additional variable is allocated and receives the remaining text on