-6

How can I fetch the details of PowerShell enabled or disabled by group policy using C#?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
manish raghu
  • 75
  • 1
  • 8
  • 1
    What mechanism are you using to disable PowerShell? From [this old question](https://stackoverflow.com/questions/29699337/disable-cmd-and-powershell-on-windows-server-2012-for-clients) there doesn't appear to be a foolproof, PowerShell-specific way of disabling it. – Rup Jul 27 '20 at 09:09
  • Welcome to https://stackoverflow.com/. For any specific problem you are having please include a https://stackoverflow.com/help/minimal-reproducible-example. Please also read https://stackoverflow.com/help/how-to-ask and https://stackoverflow.com/help/dont-ask. Make sure that your questions are specific and not overly broad, see also https://stackoverflow.com/help/on-topic. Also, be sure to take the https://stackoverflow.com/tour (you get a badge!). – Daniel Björk Jul 27 '20 at 09:21
  • 1
    I have to run a window application to check on servers whether group policies are restricting current user from running the application or not – manish raghu Jul 27 '20 at 09:33

1 Answers1

0

There is a limitation called ExecutionPolicy, setting, which can prevent from running scripts from files.

From C#, you can create an instance of InitialSessionState with ExecutionPolicy = ByPass and create Powershell with this initial session state. Then try to run your script file with Invoke-Command -FilePath command.

filimonic
  • 3,988
  • 2
  • 19
  • 26