7
votes

I'm trying to follow this article about deploying a service fabric app through powershell, but I have an issue with running the Connect-ServiceFabricCluster cmdlet. I get the following:

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

Following other articles on the internet, I've tried importing the following things:

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

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

I also saw somewhere to try and set execution policy before importing modules, so I tried this:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force -Scope CurrentUser

In the Modules section of the Powershell ISE I see the ServiceFabricSDK module, but I don't see this cmdlet.

How do I get access to these cmdlets?

Thank you for any help.

Current versions:

Running $PSVersionTable.PSVersion, I get

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

Service Fabric SDK is version 2.5.216

5
Before you do anything else, make sure you are running PowerShell x64 version, not the x86 version. Service Fabric and related cmdlets are only available on 64-bit environments.yoape
any solutions here>? i'm having the same issueAlex Gordon
Definitely try @yoape 's suggestion from the comments. I remember it didn't help me in that instance, but it's definitely something that has caused the above issue for me in the past. Otherwise, unfortunately, none of the answers below helped me. I ended up reinstalling both powershell/service fabric sdk and eventually the modules just sort of showed up in the ISE.Kolichikov

5 Answers

5
votes

Are you running x86 version of Powershell ISE? I got this error as well but when I switched to the other ISE the cmdlet was available again.

5
votes

You should make sure you are running the Windows Powershell as opposed to just Powershell. This made a difference for me.

0
votes

First, I would set your policy to bypass. This can't be done from the script itself, because, well, that's what needs to run with this policy. You could look into setting your powershell ise profile to do this for you.

Set-ExecutionPolicy Bypass

To your question. Not all modules can use the Import-Module feature. For instance, modules from the technet.microsoft.com site must sometimes be manually installed and unzipped. I'm including a script I use below to do this automatically.

    #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
votes

I was too hasty in my first answer. (which is weird, cuz it took awhile to type...) anyhow. It looks like the install process actually unpacks the psm1 for you.

  1. Be sure you are running as admin, use this to check.

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

  2. Make sure the file name you made in step 3 matches the path in step 6.

  3. When you run the import module command, follow that up with $?. This will tell you if it imported correctly. You can also use these commands to see if it worked.

    get-command -name "Cluster"; get-module

0
votes

I have just experienced the same problem on my Win10 box,

when cmdlets were not recognized as valid and downloading/installing relevant modules that contained those cmdlets didn't work.

The only solution that worked for me was as follows:

  1. Go to the Control Panel -> "Programs and Features"
  2. Uninstall Service Fabric SDK
  3. click "Turn Windows features on or off" link and uninstall PowerShell
  4. Next, reboot the Windows
  5. Go back to the Control Panel -> "Programs and Features" -> "Turn Windows features on or off"
  6. And install PowerShell
  7. After which download/install Service Fabric SDK

Once again, restart your PC, start the Service Fabric Cluster Manager (if it doesn't auto-start), then right-click its icon on the task-bar and try creating 1-node or 5-node cluster again. In my case, it took less than a minute.