Skip to content

Commit 92292f9

Browse files
authored
Fix script of getting PowerShell version (#279)
* Get correct PSVersion from PowerShell runtime * Fix script of getting PowerShell version
1 parent 71f94c8 commit 92292f9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Common/AzurePSCmdlet.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,12 @@ private string LoadPowerShellVersion()
10181018
{
10191019
try
10201020
{
1021-
var outputs = this.ExecuteScript<string>("$Host.Runspace.Version.ToString()");
1022-
return outputs[0];
1021+
var outputs = this.ExecuteScript<PSObject>("$Host.Runspace.Version");
1022+
foreach (PSObject obj in outputs)
1023+
{
1024+
string psVersion = obj.ToString();
1025+
return string.IsNullOrWhiteSpace(psVersion) ? DEFAULT_PSVERSION: psVersion;
1026+
}
10231027
}
10241028
catch (Exception e)
10251029
{

0 commit comments

Comments
 (0)