From ce2fb5159b123d4ed42b39a873d3bb6511e371bd Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 31 Aug 2018 11:38:40 -0700 Subject: [PATCH 1/2] update configs for beta36 of core tools and add windows if check --- examples/PSCoreApp/host.json | 1 + src/PowerShell/PowerShellManager.cs | 5 ++++- src/worker.config.json | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/PSCoreApp/host.json b/examples/PSCoreApp/host.json index 5553680f..c7c92e53 100644 --- a/examples/PSCoreApp/host.json +++ b/examples/PSCoreApp/host.json @@ -1,4 +1,5 @@ { + "version": "2.0", "logger": { "categoryFilter": { "defaultLevel": "Trace", diff --git a/src/PowerShell/PowerShellManager.cs b/src/PowerShell/PowerShellManager.cs index 1f30a760..713325d5 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -28,7 +28,10 @@ internal class PowerShellManager internal PowerShellManager(RpcLogger logger) { var initialSessionState = InitialSessionState.CreateDefault(); - initialSessionState.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.Unrestricted; + if(Platform.IsWindows) + { + initialSessionState.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.Unrestricted; + } _pwsh = PowerShell.Create(initialSessionState); _logger = logger; diff --git a/src/worker.config.json b/src/worker.config.json index c144335a..d5395f85 100644 --- a/src/worker.config.json +++ b/src/worker.config.json @@ -1,8 +1,8 @@ { - "Description":{ - "Language":"powershell", - "Extension":".ps1", - "DefaultExecutablePath":"dotnet", - "DefaultWorkerPath":"Azure.Functions.PowerShell.Worker.dll" + "description":{ + "language":"powershell", + "extensions":[".ps1"], + "defaultExecutablePath":"dotnet", + "defaultWorkerPath":"Azure.Functions.PowerShell.Worker.dll" } } From 71c33178b9c218b24461d5f59fe761d3a9c01f15 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 31 Aug 2018 16:27:46 -0700 Subject: [PATCH 2/2] add a comment to explain why execution policy is needed --- src/PowerShell/PowerShellManager.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PowerShell/PowerShellManager.cs b/src/PowerShell/PowerShellManager.cs index 713325d5..553b2bd1 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -28,8 +28,12 @@ internal class PowerShellManager internal PowerShellManager(RpcLogger logger) { var initialSessionState = InitialSessionState.CreateDefault(); + + // Setting the execution policy on macOS and Linux throws an exception so only update it on Windows if(Platform.IsWindows) { + // This sets the execution policy on Windows to Unrestricted which is required to run the user's function scripts on + // Windows client versions. This is needed if a user is testing their function locally with the func CLI initialSessionState.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.Unrestricted; } _pwsh = PowerShell.Create(initialSessionState);