Reputation: 29
i receive the message "Error: “|” was unexpected at this time batch script " when i run the code below:
@set CheckAccount=FOR /F "tokens=3" %A IN ('net user UserName /domain^|Findstr /ic: "active"') do SET Active=%A
%CheckAccount%
| was unexpected at this time.
Even when i change "active"
to active
. I can't seem to echo CheckAccount
without getting that error message.
Upvotes: 0
Views: 928
Reputation: 17648
There is an extra level of parsing because of the intermediate variable CheckAccount
being used. This requires escaping the problem characters twice.
@set CheckAccount=FOR /F "tokens=3" %A IN ('net user UserName /domain^^^|Findstr /ic:"active"') do SET Active=%A
The set
command will parse and store ^^^|
as ^|
into CheckAccount
, then expanding %CheckAccount%
will leave just the pipe |
.
/ic:
, thanks @Squashman for pointing that out.
Upvotes: 5