From 0706243a703361000a1e431c52be5cb7d30b3a8d Mon Sep 17 00:00:00 2001 From: Chris Hill Date: Fri, 10 Apr 2026 18:04:14 +0100 Subject: [PATCH] Fixing the logic to determine if the current PowerShell session is Windows PowerShell or PowerShell Core. --- src/code/Utils.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/code/Utils.cs b/src/code/Utils.cs index 26d3ab25e..0acef4b49 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -1161,7 +1161,6 @@ private static string GetHomeOrCreateTempHome() return s_tempHome; } - private readonly static Version PSVersion6 = new Version(6, 0); private static void GetStandardPlatformPaths( PSCmdlet psCmdlet, out string localUserDir, @@ -1169,7 +1168,7 @@ private static void GetStandardPlatformPaths( { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - string powerShellType = (psCmdlet.Host.Version >= PSVersion6) ? "PowerShell" : "WindowsPowerShell"; + string powerShellType = ((psCmdlet.GetVariableValue("PSEdition") as string) == "Core") ? "PowerShell" : "WindowsPowerShell"; localUserDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), powerShellType); allUsersDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), powerShellType); } @@ -1189,7 +1188,7 @@ private static void GetStandardPlatformPaths( public static bool GetIsWindowsPowerShell(PSCmdlet psCmdlet) { - return psCmdlet.Host.Version < PSVersion6; + return ((psCmdlet.GetVariableValue("PSEdition") as string) != "Core"); } ///