diff --git a/src/RequestProcessor.cs b/src/RequestProcessor.cs index cc720ce1..26370ee3 100644 --- a/src/RequestProcessor.cs +++ b/src/RequestProcessor.cs @@ -198,6 +198,7 @@ internal StreamingMessage ProcessFunctionLoadRequest(StreamingMessage request) // This PowerShell instance is shared by the first PowerShellManager instance created in the pool, // and the dependency manager (used to download dependent modules if needed). var pwsh = Utils.NewPwshInstance(); + LogPowerShellVersion(rpcLogger, pwsh); _powershellPool.Initialize(pwsh); // Start the download asynchronously if needed. @@ -492,6 +493,12 @@ private void BindOutputFromResult(InvocationResponse response, AzFunctionInfo fu } } + private static void LogPowerShellVersion(RpcLogger rpcLogger, System.Management.Automation.PowerShell pwsh) + { + var message = string.Format(PowerShellWorkerStrings.PowerShellVersion, Utils.GetPowerShellVersion(pwsh)); + rpcLogger.Log(isUserOnlyLog: false, LogLevel.Information, message); + } + #endregion } } diff --git a/src/Utility/Utils.cs b/src/Utility/Utils.cs index 2e3f1d1c..e661b186 100644 --- a/src/Utility/Utils.cs +++ b/src/Utility/Utils.cs @@ -6,8 +6,8 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; -using System.Threading; using Microsoft.PowerShell.Commands; namespace Microsoft.Azure.Functions.PowerShellWorker.Utility @@ -222,5 +222,15 @@ internal static bool AreDurableFunctionsEnabled() { return PowerShellWorkerConfiguration.GetBoolean("PSWorkerEnableExperimentalDurableFunctions") ?? false; } + + internal static string GetPowerShellVersion(PowerShell pwsh) + { + const string versionTableVariableName = "PSVersionTable"; + const string versionPropertyName = "PSVersion"; + + var versionTableVariable = GetGlobalVariables(pwsh).First(v => string.CompareOrdinal(v.Name, versionTableVariableName) == 0); + var versionTable = (PSVersionHashTable)versionTableVariable.Value; + return versionTable[versionPropertyName].ToString(); + } } } diff --git a/src/resources/PowerShellWorkerStrings.resx b/src/resources/PowerShellWorkerStrings.resx index 82de0ac0..11f30471 100644 --- a/src/resources/PowerShellWorkerStrings.resx +++ b/src/resources/PowerShellWorkerStrings.resx @@ -307,4 +307,7 @@ CommandNotFoundException detected (exception). + + PowerShell version: '{0}'. + \ No newline at end of file