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
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.
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
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String