Help I messed up Visual Studio Code and Connect-SPOService

Occasional Contributor

Hello,

 

Trying to connect to SPO in Powershell.  It works in the ISE, does not in VSCode

 

In VScode I tried this and got:

Connect-SPOService -url https://<Tenant-admin>.sharepoint.com
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.

 

I have done the following

Uninstalled SharePoint Online Management Shell

Reinstalled it

Went into VScode did an Install-Module Microsoft.Online.SharePoint.PowerShell:

 

WARNING: Version '16.0.22111.0' of module 'Microsoft.Online.SharePoint.PowerShell' is already installed at 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell'.
To install version '16.0.22111.12000', run Install-Module and add the -Force parameter, this command will install version '16.0.22111.12000' side-by-side with version '16.0.22111.0'.

 

Tried this:  get-module | select version,name,path

and get this

 

Version Name Path
------- ---- ----
7.0.0.0 Microsoft.PowerShell.Management C:\program files\powershell\7\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1
7.0.0.0 Microsoft.PowerShell.Utility C:\program files\powershell\7\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1
2.6.0 MicrosoftTeams C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.6.0\MicrosoftTeams.psm1
1.4.7 PackageManagement C:\program files\powershell\7\Modules\PackageManagement\PackageManagement.psm1
2.2.5 PowerShellGet C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1
2.1.0 PSReadLine C:\program files\powershell\7\Modules\PSReadLine\PSReadLine.psm1
0.0 SetMSTeamsReleaseEnvironment C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.6.0\SetMSTeamsReleaseEnvironment.ps1

 

 

In the ISE where it works:

 

PS C:\WINDOWS\system32> get-module | select version,name,path

Version Name Path
------- ---- ----
16.0.21411.12000 Microsoft.Online.SharePoint.PowerShell C:\Users\<USER>\Documents\WindowsPowerShell\Modules\Microsoft.Online.SharePoint.PowerShell\16.0.21411.12000\Microsoft.Online.SharePoint.PowerShell.dll
3.1.0.0 Microsoft.PowerShell.Management C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1
3.1.0.0 Microsoft.PowerShell.Utility C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1
2.0.0 PSReadline C:\Program Files\WindowsPowerShell\Modules\PSReadline\2.0.0\PSReadLine.psm1

 

ISE PS version:

 

Name Value
---- -----
PSVersion 5.1.19041.1320
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1320
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

 

VScode PS

 

Name Value
---- -----
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.19044
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

 

Looks like have two versions of PS and only 1 that likes Connect-SPOService.

 

Help?

 

Thanks,

 

V

7 Replies

@Vivekvp 

 

It does work in VScode, you can use import-module Microsoft.Online.SharePoint.PowerShell to get it working in PS 7 or choose PS 5 when clicking the version in the lower right bar

 

Harm_Veenstra_0-1645782206894.png

Harm_Veenstra_1-1645782226586.png

 

Hello@Harm_Veenstra,

Thank you for pointing that out!

I made that change and tried:

Install-Module -Name Microsoft.Online.SharePoint.PowerShell
But received this warning:
WARNING: Version '16.0.21411.12000' of module 'Microsoft.Online.SharePoint.PowerShell' is already installed at 'C:\program files\powershell\7\Modules\Microsoft.Online.SharePoint.PowerShell\16.0.21411.12000'. To install version '16.0.22111.12000', run Install-Module and add the -Force parameter, this command will install version '16.0.22111.12000' side-by-side with version '16.0.21411.12000'.

So I tried:

get-module


ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest 7.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature…}
Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script 1.4.7 PackageManagement {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider…}
Script 0.2.0 PowerShellEditorServices.Commands {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-ScriptExtent, Find-Ast…}
Binary 0.2.0 PowerShellEditorServices.VSCode {Close-VSCodeHtmlContentView, New-VSCodeHtmlContentView, Set-VSCodeHtmlContentView, Show-VSCodeHtmlContentView…}
Script 2.2.5 PowerShellGet {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability…}
Script 2.1.0 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}

Shouldn't I see Microsoft.Online.SharePoint.PowerShell as a module in VScode?

 

This error still occurs

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.
Thanks again,

V

get-module -listavailable shows all modules you can import, just import-module Microsoft.Online.SharePoint.PowerShell
Hi again!

I tried to import the module it and go this:

Install-Module -Name Microsoft.Online.SharePoint.PowerShell
But received this warning:
WARNING: Version '16.0.21411.12000' of module 'Microsoft.Online.SharePoint.PowerShell' is already installed at 'C:\program files\powershell\7\Modules\Microsoft.Online.SharePoint.PowerShell\16.0.21411.12000'. To install version '16.0.22111.12000', run Install-Module and add the -Force parameter, this command will install version '16.0.22111.12000' side-by-side with version '16.0.21411.12000'.

I was thinking of using -Force, but it is already installed...

How do I view what module I have installed?

Thanks,

Victor

You type install-module, but I asked if you could try import-module ;) You can view which modules you have installed using get-module -listavailable

That was helpful - so yes, I can see it is installed using get-module -listavailable !!!
Binary 16.0.2211… Microsoft.Online.SharePoint.PowerS…

But what does side by side mean in this case?

To install version '16.0.22111.12000', run Install-Module and add the -Force parameter, this command will install version '16.0.22111.12000' side-by-side with version '16.0.21411.12000'.

Thanks for your incredible patience with me!
It tells you that you have an older version installed and that you can install a newer one next to the older one (by using -force). But since you have it installed on your machine, you can use it by import-module Microsoft.Online.SharePoint.PowerShell. By using the import-module command, you tell your session to start using the module. You don't have to install it again, you already have.

So.. Try it, after running import-module Microsoft.Online.SharePoint.PowerShell you should be able to use Connect-SPOService command again in VScode.