Nicolas Klebusits
Nicolas Klebusits

Reputation: 55

How to set a "net user" output equal to a variable

I have a net user output that tells me if a user with a certain username has an active account or not. The command is as follows (followed by the command line output below):

net user "username" /domain | find /I "Account active"
Account active               Yes

how do I set a variable equal to that output? I write the following code in a batch file and it doesn't seem to be working:

set x=net user "username" /Domain | find /I "Account Active"
echo %x%

Upvotes: 0

Views: 1657

Answers (1)

Compo
Compo

Reputation: 38654

A more straightforward method would be to just pipe into another Find command.

Set "IsActive=No"
Net User "UserName" /Domain 2>Nul | Find /I "Account active" | Find /I "Yes" >Nul && Set "IsActive=Yes"

You may also prefer FindStr to deal with both at once by using a wildcard match, perhaps something as simple as active.*yes.

Upvotes: 1

Related Questions