3

I have to delete one of my SharePoint site but unfortunately I can only do it using PowerShell. However when I try to use the Connect-SPOService command, I get this error message:

Connect-SPOService: The term 'Connect-SPOService' 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.

So here is what I did:

1 – I installed the latest version of PowerShell from https://aka.ms/powershell-release?tag=stable

Note: My environment is a Windows Server 2016

2 – I installed the SharePoint Online Management Shell using the following command

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

But I tried to run the Connect-SPOService command, I got the error mentioned above.

Now the interesting thing is that when I run:

Get-Module -ListAvailable *sharepoint*, I get this

Directory: D:\Users\<path of my business OneDrive>\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     16.0.2151…            Microsoft.Online.SharePoint.PowerS… Desk

Why is the ExportedCommands is empty?

Why did the SharePoint Online Management Shell get installed under my OneDrive path and not under the location where PowerShell 7 got installed which is “C:\Program Files\PowerShell\7”

What can I do so the Connect-SPOService command works?

1 Answer 1

1

It looks like the issue is with the different DLLs in your Global Assembly Cache (GAC). Run this command and check the output:

Get-ChildItem -Path C:\Windows\Microsoft.NET\assembly\GAC_MSIL\*Microsoft.SharePoint*.dll -Recurse | ft Name,@{Label="Version";Expression={$_.VersionInfo.FileVersion}} -AutoSize

If the file versions are different, that's your problem. Remove one and test it.

Check this article for full, detailed instructions: The term ‘Connect-SPOService’ is not recognized.

4
  • I saw the above post before posting my issue. The DLLs have the same version ---- ------- Microsoft.SharePoint.BusinessData.Administration.Client.dll 15.0.4420.1017 Microsoft.SharePoint.BusinessData.Administration.Client.Intl.dll 15.0.4420.1017 Microsoft.SharePoint.Client.Runtime.Local.Resources.dll 15.0.4420.1017 Commented Sep 5, 2021 at 15:07
  • the dll you posted above are not the correct, you have to check the Microsoft.SharePoint.Client dlls.
    – Waqas Sarwar MVP
    Commented Sep 5, 2021 at 17:57
  • See my question above > Why did the SharePoint Online Management Shell get installed under my OneDrive path and not under the location where PowerShell 7 got installed which is “C:\Program Files\PowerShell\7” Commented Sep 5, 2021 at 22:16
  • I found this command from your linked article helpful in seeing what version was installed and whether Exported Commands was empty, but it did not help in actually resolving my issue. I had to add Import-Module Microsoft.Online.SharePoint.PowerShell to my script (with the -DisableNameChecking flag to silence 'undiscoverable name' warnings, and since I was using PowerShell 7, I apparently also needed the -UseWindowsPowerShell flag, too).
    – TylerH
    Commented Nov 28, 2023 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.