Skip to content

Commit 2370855

Browse files
authored
Log PowerShell version (#396) (#397)
1 parent 408c8bf commit 2370855

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/RequestProcessor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ internal StreamingMessage ProcessFunctionLoadRequest(StreamingMessage request)
198198
// This PowerShell instance is shared by the first PowerShellManager instance created in the pool,
199199
// and the dependency manager (used to download dependent modules if needed).
200200
var pwsh = Utils.NewPwshInstance();
201+
LogPowerShellVersion(rpcLogger, pwsh);
201202
_powershellPool.Initialize(pwsh);
202203

203204
// Start the download asynchronously if needed.
@@ -492,6 +493,12 @@ private void BindOutputFromResult(InvocationResponse response, AzFunctionInfo fu
492493
}
493494
}
494495

496+
private static void LogPowerShellVersion(RpcLogger rpcLogger, System.Management.Automation.PowerShell pwsh)
497+
{
498+
var message = string.Format(PowerShellWorkerStrings.PowerShellVersion, Utils.GetPowerShellVersion(pwsh));
499+
rpcLogger.Log(isUserOnlyLog: false, LogLevel.Information, message);
500+
}
501+
495502
#endregion
496503
}
497504
}

src/Utility/Utils.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using System;
77
using System.Collections.Generic;
88
using System.IO;
9+
using System.Linq;
910
using System.Text;
10-
using System.Threading;
1111
using Microsoft.PowerShell.Commands;
1212

1313
namespace Microsoft.Azure.Functions.PowerShellWorker.Utility
@@ -222,5 +222,15 @@ internal static bool AreDurableFunctionsEnabled()
222222
{
223223
return PowerShellWorkerConfiguration.GetBoolean("PSWorkerEnableExperimentalDurableFunctions") ?? false;
224224
}
225+
226+
internal static string GetPowerShellVersion(PowerShell pwsh)
227+
{
228+
const string versionTableVariableName = "PSVersionTable";
229+
const string versionPropertyName = "PSVersion";
230+
231+
var versionTableVariable = GetGlobalVariables(pwsh).First(v => string.CompareOrdinal(v.Name, versionTableVariableName) == 0);
232+
var versionTable = (PSVersionHashTable)versionTableVariable.Value;
233+
return versionTable[versionPropertyName].ToString();
234+
}
225235
}
226236
}

src/resources/PowerShellWorkerStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,7 @@
307307
<data name="CommandNotFoundException_Exception" xml:space="preserve">
308308
<value>CommandNotFoundException detected (exception).</value>
309309
</data>
310+
<data name="PowerShellVersion" xml:space="preserve">
311+
<value>PowerShell version: '{0}'.</value>
312+
</data>
310313
</root>

0 commit comments

Comments
 (0)