使用 Powershell 时找不到 Connect-ServiceFabricCluster cmdlet

Kol*_*kov 7 powershell azure azure-powershell powershell-4.0 azure-service-fabric

我试图按照文章有关通过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
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

Service Fabric SDK 版本为 2.5.216

小智 6

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


小智 5

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


小智 0

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

\n\n
Set-ExecutionPolicy Bypass\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

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