【问题标题】:Can't find the Connect-ServiceFabricCluster cmdlet when using Powershell使用 Powershell 时找不到 Connect-ServiceFabricCluster cmdlet
【发布时间】:2017-09-07 04:32:41
【问题描述】:

我正在尝试关注 this 关于通过 powershell 部署服务结构应用程序的文章,但我在运行 Connect-ServiceFabricCluster cmdlet 时遇到问题。我得到以下信息:

Connect-ServiceFabricCluster : The term 'Connect-ServiceFabricCluster' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, 
or if a path was included, verify that the path is correct and try again.
At line:1 char:2
+  Connect-ServiceFabricCluster
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Connect-ServiceFabricCluster:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

根据互联网上的其他文章,我尝试导入以下内容:

Import-Module "$ENV:ProgramW6432\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1"

Import-Module "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ServiceFabric"

我还看到了在导入模块之前尝试设置执行策略的地方,所以我尝试了这个:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force -Scope CurrentUser

在 Powershell ISE 的“模块”部分中,我看到了 ServiceFabricSDK 模块,但没有看到此 cmdlet。

如何访问这些 cmdlet?

感谢您的帮助。

当前版本:

运行 $PSVersionTable.PSVersion,我明白了

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

Service Fabric SDK 是 2.5.216 版

【问题讨论】:

  • 在您执行任何其他操作之前,请确保您运行的是 PowerShell x64 版本,而不是 x86 版本。 Service Fabric 和相关 cmdlet在 64 位环境中可用。
  • 这里有什么解决方案>?我也有同样的问题
  • 一定要试试 @yoape 来自 cmets 的建议。我记得在那种情况下它对我没有帮助,但这绝对是过去给我造成上述问题的原因。否则,不幸的是,以下答案都没有帮助我。我最终重新安装了 powershell/service fabric sdk,最终这些模块在 ISE 中出现了。

标签: powershell azure azure-service-fabric powershell-4.0 azure-powershell


【解决方案1】:

您是否正在运行 x86 版本的 Powershell ISE?我也遇到了这个错误,但是当我切换到另一个 ISE 时,cmdlet 再次可用。

【讨论】:

    【解决方案2】:

    您应该确保您运行的是 Windows Powershell,而不仅仅是 Powershell。这对我来说很重要。

    【讨论】:

      【解决方案3】:

      首先,我会将您的策略​​设置为绕过。这不能从脚本本身完成,因为,这就是需要使用此策略运行的内容。您可以考虑设置您的 powershell ise 配置文件来为您执行此操作。

      Set-ExecutionPolicy Bypass
      

      你的问题。并非所有模块都可以使用 Import-Module 功能。例如,来自 technet.microsoft.com 站点的模块有时必须手动安装和解压缩。我在下面包含一个脚本来自动执行此操作。

          #https://www.petri.com/manage-windows-updates-with-powershell-module\
          $url = "https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/file/41459/47/PSWindowsUpdate.zip"
          $module = "PSWindowsUpdate"
          $zipped = "$($PSScriptRoot)\$($module).zip"
          $unzipped = "C:\Windows\System32\WindowsPowerShell\v1.0\Modules"
          #$unzipped = "$PSScriptRoot\$($module)"
      
          if (Get-Module -Name $($module)) {
                 Write-Host "Module exists $($module)"
              } else {
                 Write-Host "Getting Module $($module)"
      
          if(!(Test-Path $zipped)){
              (New-Object System.Net.WebClient).DownloadFile($url, $zipped)
              if($?){Write-Output "Downloaded zip $($zipped)"}
          }else{
              Write-Output "Zip found $($zipped)"
          }
      
          if(!(test-path "$($unzipped)\$($module)")){
          Add-Type -assembly “system.io.compression.filesystem”
          [io.compression.zipfile]::ExtractToDirectory($zipped, $unzipped)
          if($?){Write-Output "Unzipped to $($unzipped)"}
      }
          Unblock-File -Path "$($unzipped)\$($module)" -Confirm
          if($?){Write-Output "Unblocked file $($unzipped)"}
      
          Import-Module $unzipped\*\$($module).psd1 -Verbose
          if($?){Write-Output "Imported module $($unzipped)"}        
      }
      

      【讨论】:

      • 注意:“Unblock-File cmdlet 允许您打开从 Internet 下载的文件。它取消阻止从 Internet 下载的 Windows PowerShell 脚本文件,以便您可以运行它们,即使在 Windows PowerShell执行策略是 RemoteSigned。默认情况下,这些文件被阻止以保护计算机免受不受信任的文件的侵害。” msdn.microsoft.com/en-us/powershell/reference/5.1/…
      【解决方案4】:

      我的第一个答案太仓促了。 (这很奇怪,因为输入需要一段时间......)无论如何。看起来安装过程实际上为您解压了 psm1。

      1. 确保您以管理员身份运行,使用它来检查。

        ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(` [Security.Principal.WindowsBuiltInRole] “管理员”)

      2. 确保您在第 3 步中创建的文件名与第 6 步中的路径匹配。

      3. 当您运行导入模块命令时,使用 $? 跟进。这将告诉您它是否正确导入。您也可以使用这些命令来查看它是否有效。

        get-command -name "集群";获取模块

      【讨论】:

      • 3. 的输出应该是什么样的?我在列表中看到了 ServiceFabricSDK,它是 Script 类型,版本为 0.0,我看到了一些导出的命令,但不是所有预期的命令。
      【解决方案5】:

      我刚刚在我的Win10 盒子上遇到了同样的问题,

      cmdlets 未被识别为有效并且无法下载/安装包含这些 cmdlet 的相关模块时。

      对我有用的唯一解决方案如下:

      1. 进入控制面板->“程序和功能”
      2. 卸载 Service Fabric SDK
      3. 单击“打开或关闭 Windows 功能”链接并卸载 PowerShell
      4. 接下来,重新启动 Windows
      5. 返回控制面板 -> “程序和功能” -> “打开或关闭 Windows 功能”
      6. 并安装 PowerShell
      7. 然后下载/安装 Service Fabric SDK

      再次重新启动您的 PC,启动 Service Fabric 集群管理器(如果它没有自动启动),然后右键单击任务栏上的图标并尝试再次创建 1 节点或 5 节点集群.就我而言,不到一分钟。

      【讨论】:

        猜你喜欢
        • 2019-11-17
        • 2016-12-21
        • 2016-10-06
        • 2019-07-09
        • 2021-02-11
        • 2017-07-01
        • 2013-12-05
        • 1970-01-01
        • 2016-11-01
        相关资源
        最近更新 更多