# RunProcess PowerShell command to obtain Active Directory groups

Is it possible to run this Windows cmd command in RunProcess?

powershell "([ADSISEARCHER]\"samaccountname=$($env:USERNAME)\").Findone().Properties.memberof -replace '^CN=([^,]+).+$','$1'"


The shorter version below does not return the same output as the Windows command line, although it does not error. The output is useless though.

RunProcess[$SystemShell, "StandardOutput", "powershell ([ADSISEARCHER]\"samaccountname=$($env:USERNAME)\").Findone().Properties.memberof"]  Actually the output is the same as for this different command. RunProcess[$SystemShell,
"StandardOutput",
"whoami /groups"]


However, this can be successfully run in slightly different syntax:

RunProcess[{"whoami", "/groups"}, "StandardOutput"]


(Successful in the sense that it runs, but it fails to report all the groups that the powershell method correctly does.)

For what it's worth

The following works in Windows but hangs in Citrix.

 RunProcess[{"powershell", "Get-Help"}, "StandardOutput"]


The following gives the useless output in Windows and Citrix (surprisingly).

RunProcess[\$SystemShell, "StandardOutput", "powershell Get-Help"]


The following gives useful output in Windows but just returns an empty list in Citrix.

ReadList["!powershell Get-Help", String]


Last resort

Use the much slower gpresult -- slower because it does lots of other things.

RunProcess[{"gpresult", "/r", "/scope:user"}, "StandardOutput"]

• Why would it not be? If you're running into troubles my guess is that the environment path variable isn't quite what it is in your terminal. – b3m2a1 Jul 19 '18 at 10:11
• @b3m2a1 Can you elaborate? My system admin and I cannot use your info. – Chris Degnen Jul 19 '18 at 10:43
• Without knowing what your error is I can't be certain, but my guess is that ProcessEnvironment can't find the executable because whatever path variable in Environment Windows uses is different from its corresponding value on the command line. – b3m2a1 Jul 19 '18 at 10:47