Trouble Importing SharePoint Online Module in PowerShell 7

0
4
Asked By CuriousCat911 On

Hey everyone! I'm having a bit of trouble when trying to import the SharePoint Online PowerShell module into my PowerShell 7 (PSv7) session using a script. When I run the import command manually in my PSv7 terminal, it works perfectly, and I can use the cmdlets from the module. Here's the command I'm running: `Import-module -name "$PSModuleRootMicrosoft.Online.SharePoint.PowerShell16.0.26017.12000Microsoft.Online.SharePoint.PowerShell.psd1" -UseWindowsPowerShell`. However, when I place this command inside a script and run it, the cmdlets aren't available. Any thoughts on what's going wrong?

2 Answers

Answered By TechieTinker On

It sounds like you're running into compatibility issues. PowerShell only allows compatibility mode for modules that are in the PowerShell 5.1 default directory. Since your module isn't located there, you’ve got to make sure to explicitly import it using the `-UseWindowsPowerShell` flag. Check out the documentation on Windows PowerShell compatibility for some extra details.

Answered By ScriptWizard77 On

I think you might be on the right track with your command. If the legacy module is within your custom module structure, ensure it’s being referenced correctly in your script. Sometimes, when you're packaging commands in a function, the context might get altered. Make sure you're not losing the session context when calling your `Initialise-PreReqs` function.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.