6

I have changed many powershell policies, such as the Execution policy for running scripts. Is there a way to get everything back to the default settings when OS was installed?

2 Answers 2

4

There is a PowerShell profile file, usually at C:\Users\UserA\Documents\WindowsPowerShell that you can edit/remove some customization entries.

When it comes to "resetting services" that is probably something that can be done manually.

e.g. for Execution Policy

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Undefined

Additionally, check C:\Users\UserA\Documents\PowerShell\powershell.config.json you can actually changed execution policy from there

0
0

Here is how:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7#parameters

https://docs.microsoft.com/en-us/dotnet/api/microsoft.powershell.executionpolicy?view=powershellsdk-7.0.0

Default. Sets the default execution policy. Restricted for Windows clients or RemoteSigned for Windows servers.

Get-ExecutionPolicy ; Get-ExecutionPolicy -List | Format-Table -AutoSize
#Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes must
be set through Group Policy.
Set-Executionpolicy -Scope Process -ExecutionPolicy Default -Force
Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy Default -Force
Set-Executionpolicy -Scope LocalMachine -ExecutionPolicy Default -Force
Get-ExecutionPolicy ; Get-ExecutionPolicy -List | Format-Table -AutoSize

Eg:

PS C:\Users\Admin> Get-ExecutionPolicy ; Get-ExecutionPolicy -List | Format-Table -AutoSize
Restricted

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser      Restricted
 LocalMachine      Restricted


PS C:\Users\Admin> Set-Executionpolicy -Scope MachinePolicy -ExecutionPolicy Default -Force
Set-Executionpolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes must
be set through Group Policy.
At line:1 char:1
+ Set-Executionpolicy -Scope MachinePolicy -ExecutionPolicy Default -Fo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Set-ExecutionPolicy], InvalidOperationException
    + FullyQualifiedErrorId : CantSetGroupPolicy,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
PS C:\Users\Admin> Set-Executionpolicy -Scope UserPolicy -ExecutionPolicy Default -Force
Set-Executionpolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes must
be set through Group Policy.
At line:1 char:1
+ Set-Executionpolicy -Scope UserPolicy -ExecutionPolicy Default -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Set-ExecutionPolicy], InvalidOperationException
    + FullyQualifiedErrorId : CantSetGroupPolicy,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
PS C:\Users\Admin> Set-Executionpolicy -Scope Process -ExecutionPolicy Default -Force
PS C:\Users\Admin> Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy Default -Force
PS C:\Users\Admin> Set-Executionpolicy -Scope LocalMachine -ExecutionPolicy Default -Force
PS C:\Users\Admin> Get-ExecutionPolicy ; Get-ExecutionPolicy -List | Format-Table -AutoSize
Restricted

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process      Restricted
  CurrentUser      Restricted
 LocalMachine      Restricted

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.