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.

 "powershell ([ADSISEARCHER]\"samaccountname=$($env:USERNAME)\").Findone().Properties.memberof"]

Actually the output is the same as for this different command.

 "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"]
  • $\begingroup$ 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. $\endgroup$ – b3m2a1 Jul 19 '18 at 10:11
  • $\begingroup$ @b3m2a1 Can you elaborate? My system admin and I cannot use your info. $\endgroup$ – Chris Degnen Jul 19 '18 at 10:43
  • $\begingroup$ 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. $\endgroup$ – b3m2a1 Jul 19 '18 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.