2

I have WebApp and Webjob in Azure. My webjob tries to run some powershell scripts using PowerShell.Create() then ps.AddScript(script) and ps.Invoke(). In my local environment webjob works well and all ps scripts are executed correctly. But in Azure webjobs throws following fail:

One or more errors occurred. (File D:\local\Temp...\Login.ps1 cannot be loaded because running scripts are disabled on this system. For more information, see about_Execution_Policies.

After that I try to set execution policy as urestricted but this command doesn't work in azure console.

My current execution policy:

MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    RemoteSigned

I have tried the following ways to change execution policy(I run all commands in azure portal console):

Set-ExecutionPolicy Unrestricted

Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\M
icrosoft\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. 

But I don't know how to run the console in Azure as Administrator.

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

Set-Executionpolicy : The specified registry key does not exist.
At line:1 char:1
+ Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy UnRestricted

How to change ExecutionPolicy in Azure? Or how to avoid issue with disabling ps scripts? Please, help me!)

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
agawa17
  • 315
  • 1
  • 3
  • 10

1 Answers1

1

Azure Shell (I think you mean this with Azure Portal Console) has nothing to do with your Azure App Service. Have you tried setting the policy in C# code instead?

Kexy Biscuit
  • 390
  • 3
  • 11