0

我正在尝试关注通过PowerShell部署服务结构应用的this文章,但运行Connect-ServiceFabricCluster cmdlet时遇到问题。我得到如下:使用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 

服务织物SDK版本为2.5.216

+1

在做其他事情之前,请确保您运行的是PowerShell x64版本,而不是x86版本。服务结构和相关的cmdlet *仅*可在64位环境中使用。 – yoape

回答

0

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

Set-ExecutionPolicy Bypass 

对你的问题。并非所有模块都可以使用导入模块功能。例如,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)"}   
} 
+0

注意:“Unblock-File cmdlet允许您打开从Internet下载的文件,它可以解除从互联网下载的Windows PowerShell脚本文件,以便您可以运行它们,即使Windows PowerShell执行策略是RemoteSigned。 ,这些文件被阻止以保护计算机免受不可信文件的攻击。“ https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/unblock-file – primohacker

0

我在我的第一个回答中太仓促了。 (这很奇怪,因为它需要一段时间才能输入...)无论如何。看起来安装过程实际上是为你解开psm1的。

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

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

  2. 确保文件名在第6步

  3. 当您运行导入模块命令则步骤3场比赛的路径,遵循了$?这会告诉你它是否正确导入。您也可以使用这些命令来查看它是否工作。

    get-command -name“Cluster”; get-module

+0

3.应该输出什么内容?我在列表中看到ServiceFabricSDK,它的类型为Script,版本为0.0,我看到一些导出的命令,但不是所有预期的命令。 – snaits

1

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

相关问题