Skip to content

Commit 24150dd

Browse files
authored
Use $PSVersionTable.PSVersion for PowerShell Version (#372)
Currently, we use $Host.runspace.version for PowerShell version. It is the PowerShell engine version, and should be same as the $psversiontable.psversion, but runspace will be null in some cases for example when developers directly use PowerShell SDK as below. ``` # $sp = [runspaceFactory]::CreateRunspace() # Create an space with default host # $ps = [powershell]::create() # create an powershell object # $ps.Runspace = $sp # $sp.Open() # $ps.AddScript{Get-host}.Invoke() # runspace is null for such an case ```
1 parent f458acf commit 24150dd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Common/AzurePSCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ private string LoadPowerShellVersion()
10651065
{
10661066
try
10671067
{
1068-
var outputs = this.ExecuteScript<PSObject>("$Host.Runspace.Version");
1068+
var outputs = this.ExecuteScript<PSObject>("$PSVersionTable.PSVersion");
10691069
foreach (PSObject obj in outputs)
10701070
{
10711071
string psVersion = obj.ToString();

0 commit comments

Comments
 (0)