Forum Discussion
KatoBaade
Jul 14, 2021Copper Contributor
MSOnline not working in PowerShell 7
Greetings,
I have installed Windows Terminal with PowerShell 7.1.1 for use with requests related to work as a L1 support tech.
I use PowerShell mainly for Exchange-related affairs but from time to time I need to connect to Azure services, for example, to retrieve a list of users easily. To do this, I use the module MSOnline which I installed on my PowerShell instance.
The problem appears when I try using Connect-MsolService on PowerShell 7.1.1 I get an error saying the cmdlet does not exist, but when I list available modules it does show in the list. Connect-MsolService works as intended on 5.1 shipped with Windows, which has been my workaround for the past weeks. But I'd prefer having this up and running.
TIA for any answers, and apologies if my English has minor errors, as it is not my mother tongue.
- On Windows, with PowerShell 5.1 installed, one can import PowerShell modules into a "compatability session". The way you do this is to make sure the PowerShell module is installed using PowerShell 5.1, and using PowerShell 7+ on Windows you can do:
Import-Module MSOnline -UseWindowsPowershell
After this, you can run those cmdlets like you normally would.
6 Replies
Sort By
- pvanberloSteel ContributorOn Windows, with PowerShell 5.1 installed, one can import PowerShell modules into a "compatability session". The way you do this is to make sure the PowerShell module is installed using PowerShell 5.1, and using PowerShell 7+ on Windows you can do:
Import-Module MSOnline -UseWindowsPowershell
After this, you can run those cmdlets like you normally would.- tiddliwinkinsCopper Contributor
These instructions worked for me as well; however, I have a {username}@ after the prompt and I am reticent to execute until I understand the scope/implications of it being at the start of a script I paste in. Does anyone have any knowledge on that?
- DannthemanCopper Contributor
- RickkeeCCopper ContributorAre you doubting it yet? Only took me a day and ran screaming and crying back to PS 5.1. Leave it to Beaver...I mean MicroSlop...Another fine half-baked mess you've gotten us into Ollie
- KatoBaadeCopper ContributorThanks! This works, but do I need to do this for every new PS instance I run?
- pvanberloSteel ContributorYes. However, one could decide to add this into a profile script so it’s executed in PowerShell session start.
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.1