service-fabric icon indicating copy to clipboard operation
service-fabric copied to clipboard

[BUG] SDK is not accessible via PowerShell 7.X only 5.1

Open jwyglendowski-precisionlender opened this issue 2 years ago • 2 comments

Describe the bug Running power shell scripts using imports do not work in PowerShell 7.x only 5.1. The following works fine on the same machine in 5.1 but not 7.x.

Area/Component: SDK with PowerShell 7.x

To Reproduce Steps to reproduce the behavior:

  1. Open powershell in version 7.x
  2. Run the following
$RegKey = "HKLM:\SOFTWARE\Microsoft\Service Fabric SDK"
$ModuleFolderPath = (Get-ItemProperty -Path $RegKey -Name FabricSDKPSModulePath).FabricSDKPSModulePath
Import-Module "$ModuleFolderPath\ServiceFabricSDK.psm1"

Connect-ServiceFabricCluster localhost:19000 | Out-Null

Test two

  1. Open powershell in version 7.x
  2. Run the following Get-Command *ServiceFabricCluster* -All
  3. Open powershell in version 5.1
  4. Run the following Get-Command *ServiceFabricCluster* -All Notice 5.1 has all the expected commands and 7.x does not.

Expected behavior In 5.1

PS C:\code> Get-Command *ServiceFabricCluster* -All


CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Add-AzureRmServiceFabricClusterCertificate         0.3.4      AzureRM.ServiceFabric
Cmdlet          Connect-ServiceFabricCluster                       3.1.0.0    ServiceFabric
Cmdlet          Copy-ServiceFabricClusterPackage                   3.1.0.0    ServiceFabric
Cmdlet          Get-AzureRmServiceFabricCluster                    0.3.4      AzureRM.ServiceFabric
Cmdlet          Get-ServiceFabricClusterConfiguration              3.1.0.0    ServiceFabric
Cmdlet          Get-ServiceFabricClusterConfigurationUpgradeStatus 3.1.0.0    ServiceFabric
Cmdlet          Get-ServiceFabricClusterConnection                 3.1.0.0    ServiceFabric
Cmdlet          Get-ServiceFabricClusterHealth                     3.1.0.0    ServiceFabric
Cmdlet          Get-ServiceFabricClusterHealthChunk                3.1.0.0    ServiceFabric
Cmdlet          Get-ServiceFabricClusterLoadInformation            3.1.0.0    ServiceFabric
Cmdlet          Get-ServiceFabricClusterManifest                   3.1.0.0    ServiceFabric
Cmdlet          Get-ServiceFabricClusterUpgrade                    3.1.0.0    ServiceFabric
Cmdlet          New-AzureRmServiceFabricCluster                    0.3.4      AzureRM.ServiceFabric
Cmdlet          New-ServiceFabricCluster                           3.1.0.0    ServiceFabric
Cmdlet          Register-ServiceFabricClusterPackage               3.1.0.0    ServiceFabric
Cmdlet          Remove-AzureRmServiceFabricClusterCertificate      0.3.4      AzureRM.ServiceFabric
Cmdlet          Remove-ServiceFabricCluster                        3.1.0.0    ServiceFabric
Cmdlet          Remove-ServiceFabricClusterPackage                 3.1.0.0    ServiceFabric
Cmdlet          Resume-ServiceFabricClusterUpgrade                 3.1.0.0    ServiceFabric
Cmdlet          Send-ServiceFabricClusterHealthReport              3.1.0.0    ServiceFabric
Cmdlet          Start-ServiceFabricClusterConfigurationUpgrade     3.1.0.0    ServiceFabric
Cmdlet          Start-ServiceFabricClusterRollback                 3.1.0.0    ServiceFabric
Cmdlet          Start-ServiceFabricClusterUpgrade                  3.1.0.0    ServiceFabric
Cmdlet          Test-ServiceFabricClusterConnection                3.1.0.0    ServiceFabric
Cmdlet          Test-ServiceFabricClusterManifest                  3.1.0.0    ServiceFabric
Cmdlet          Test-ServiceFabricClusterUpgrade                   3.1.0.0    ServiceFabric
Cmdlet          Unregister-ServiceFabricClusterPackage             3.1.0.0    ServiceFabric
Cmdlet          Update-ServiceFabricClusterUpgrade                 3.1.0.0    ServiceFabric

Observed behavior:

PS C:\code> Get-Command *ServiceFabricCluster* -All

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Add-AzureRmServiceFabricClusterCertificate         0.3.4      AzureRM.ServiceFabric
Cmdlet          Get-AzureRmServiceFabricCluster                    0.3.4      AzureRM.ServiceFabric
Cmdlet          New-AzureRmServiceFabricCluster                    0.3.4      AzureRM.ServiceFabric
Cmdlet          Remove-AzureRmServiceFabricClusterCertificate      0.3.4      AzureRM.ServiceFabric
The term 'Connect-ServiceFabricCluster' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a
     | path was included, verify that the path is correct and try again.

Service Fabric Runtime Version: Microsoft Azure Service Fabric 8.2.1571.9590 Microsoft Azure Service Fabric SDK 5.2.1571.9590

Environment:

  • Microsoft Windows 10 Enterprise
  • Version 10.0.19044 Build 19044
  • System Type x64-based PC

Additional context PowerShell 7.x is coming directly from the Windows Store. Running these in VS Code terminals. Version: 1.66.2 (system setup) Commit: dfd34e8260c270da74b5c2d86d61aee4b6d56977 Date: 2022-04-11T07:46:01.075Z Electron: 17.2.0 Chromium: 98.0.4758.109 Node.js: 16.13.0 V8: 9.8.177.11-electron.0 OS: Windows_NT x64 10.0.19044


Assignees: /cc @microsoft/service-fabric-triage

There is no out of box support on PowerShell 7, but ServiceFabric module can be loaded and used in PS7 with this command:

Import-Module ServiceFabric -UseWindowsPowerShell

dacken avatar Nov 05 '22 13:11 dacken

Thanks @dacken. Not the out of the box experience I was hoping for but in case someone else has the same issue I have added the Import-Module ServiceFabric -UseWindowsPowerShell to my Powershell profile so it essentially does exactly what I need. Just do the following:

  1. PS> code $PROFILE
  2. Add Import-Module ServiceFabric -UseWindowsPowerShell to the file and save.

Each time a PS session starts it will run that statement.