Hi, All.
I’m writing this script. The first section of the script is to check and make sure the required modules are loaded in the session to run the different commands. I know I’m missing something small on this but I can’t get the script to find the GroupPolicy module like the rest of the modules. Here’s a screenshot of what I mean from VS Code:
I’m not sure why, but the script will find all the modules except GroupPolicy. But in a separate sessions I can see it, import it… whatever.
What am I missing?
Thanks,
Dale
What’s the actual output of that particular Get-Module instance from the script? Maybe as a test instead of capturing it in a variable just dump it do console and add the -Verbose parameter too?
You may also look at the Requires statement as an option.
Looks like I have fallen victim to versioning. When I run the script in VS Code, it’s running everything in PS 7.3.9. If I launch a terminal window from within VS Code, it opens PS 5. I have everything already setup for 5, but not 7. Which is why I was getting the missing module stuffs.
So, thanks for the reply. Hope this makes sense…
yeah I think i’m tracking. I’m glad you figured it out, cause that kinda stuff drives me crazy.
It’s still worth taking a look at that Requires statement that I linked. I’ve used that in several of my scripts to replace long sanity check areas, and as far as I know it’s backwards compatible to at least v3.
Sometimes I still manually check for modules if I want to do something custom upon failure like write a pretty message to the console, or log the reason why the script exited to a file.