From dc9b3265871629d464c5227bba251c9ce14e3fa5 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Fri, 5 Aug 2016 11:19:32 -0700 Subject: [PATCH] Fix issue #1609 - Get-PSSession -computername fails on nano Root cause: Microsoft.WSMan.Management and Microsoft.PowerShell.Commands.Diagnostics are not put in the default snapin list for win-ops, and thus when a runspace is created using RunspaceConfiguration, those 2 are not loaded as snapins by default, which is a behavior change compared to Nano PS. Fix: Replace the guard 'PORTABLE' to be 'UNIX' so that they are in the default snapin list when targeting windows platform. --- .../singleshell/config/MshSnapinInfo.cs | 4 ++-- test/powershell/engine/BasicEngine.Tests.ps1 | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs index 6549e73455..e3462deb09 100644 --- a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs +++ b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs @@ -1284,7 +1284,7 @@ namespace System.Management.Automation { s_defaultMshSnapins = new List() { -#if !PORTABLE // Microsoft.PowerShell.Commands.Diagnostics.dll needs to be ported +#if !UNIX new DefaultPSSnapInInformation("Microsoft.PowerShell.Diagnostics", "Microsoft.PowerShell.Commands.Diagnostics", null, "GetEventResources,Description", "GetEventResources,Vendor"), #endif @@ -1303,7 +1303,7 @@ namespace System.Management.Automation "SecurityMshSnapInResources,Description","SecurityMshSnapInResources,Vendor") }; -#if !PORTABLE +#if !UNIX if (!Utils.IsWinPEHost()) { s_defaultMshSnapins.Add(new DefaultPSSnapInInformation("Microsoft.WSMan.Management", "Microsoft.WSMan.Management", null, diff --git a/test/powershell/engine/BasicEngine.Tests.ps1 b/test/powershell/engine/BasicEngine.Tests.ps1 index e51c778b3b..eaa1e429e9 100644 --- a/test/powershell/engine/BasicEngine.Tests.ps1 +++ b/test/powershell/engine/BasicEngine.Tests.ps1 @@ -3,5 +3,14 @@ Describe 'Basic engine APIs' -Tags "CI" { It 'can create default instance' { [powershell]::Create() | Should Not Be $null } + + It "can load the default snapin 'Microsoft.WSMan.Management'" -skip:(-not $IsWindows) { + $ps = [powershell]::Create() + $ps.AddScript("Get-Command -Name Test-WSMan") > $null + + $result = $ps.Invoke() + $result.Count | Should Be 1 + $result[0].PSSnapIn.Name | Should Be "Microsoft.WSMan.Management" + } } }