PowerShell indique "l'exécution de scripts est désactivée sur ce système."

PowerShell indique “l’exécution de scripts est désactivée sur ce système.”


Source : Stack Overflow [powershell]

Si vous utilisez Windows Server 2008 R2, il existe une version x64 et une version x86 de PowerShell et les deux doivent avoir leurs politiques d’exécution définies. Avez-vous défini la politique d’exécution sur les deux hôtes ?

En tant qu’administrateur, vous pouvez définir la politique d’exécution en tapant ceci dans votre fenêtre PowerShell :

`Set-ExecutionPolicy RemoteSigned


Pour plus d'informations, consultez *[Using the Set-ExecutionPolicy Cmdlet](https://learn.microsoft.com/powershell/module/microsoft.powershell.security/set-executionpolicy)*.

Lorsque vous avez terminé, vous pouvez rétablir la politique à sa valeur par défaut avec :

`Set-ExecutionPolicy Restricted

Vous pourriez voir une erreur :

`Access to the registry key
‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell’ is denied.
To change the execution policy for the default (LocalMachine) scope,
start Windows PowerShell with the “Run as administrator” option.
To change the execution policy for the current user,
run “Set-ExecutionPolicy -Scope CurrentUser”.


Vous devrez donc peut-être exécuter la commande comme ceci (comme indiqué dans les commentaires) :

`Set-ExecutionPolicy RemoteSigned -Scope CurrentUser