How to let wmic command(s) that within environment variable can run properly in Powershell window?

In Windows 10 V1703, now right-click on Start button, there shows "Windows PowerShell (Admin)" which replaced old "Command Prompt (Admin)".

In a PowerShell window, can run well the below command:
net user $env:UserName

Now in Cortana's search box type "cmd", then right-click "Command Prompt", click "Run as administrator", open a "Command Prompt (Admin)" window,

can run well the below command in it:
net user %UserName%


This indicates that the environment variable $env:UserName in PS is equal to %UserName% in CMD.

And, in a "Command Prompt (Admin)" window, can run well the below two commands in it:

Get the current account's username:
wmic useraccount where name="%UserName%" get Name

View a specific user account info list:
wmic useraccount where name="[username]" list
for example, list my user account:
wmic useraccount where name="Trybird" list


Now in a PowerShell window, I try to run the following commands, but all have failed:
wmic useraccount where name="$env:UserName" get Name
wmic useraccount where name=$env:UserName get Name
wmic useraccount where name="Trybird" list
wmic useraccount where name=Trybird list

Please tell me,
which PowerShell scripts are equal to the CMD commands --
wmic useraccount where name="[username]" list
and
wmic useraccount where name="%UserName%" get Name?

Answer
Answer
You're wasting your time discussing PowerShell issues in this forum (whose focus is Windows 10 Performance). You would get excellent replies to the points you raise in the scripting forum I gave you before.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated May 25, 2018 Views 2,002 Applies to: