Make PowerShell script run cmdlets in global scope

Question:

I have written the following PowerShell script:

The only problem with this script is that Import-Module only applies inside that script’s scope – it does not import the module in the global scope. Is there any way to make a script import a module so that it stays around after the script finishes?

Note: dot-sourcing like so: . Reload-Module MyModuleName does not work.

Answer:

From the Powershell help:

v3 also adds the -Scope parameter, which is a little more general:

Note: the above help snippets are from v3.0 which is what I have installed on my system. The v2.0 help is available at http://msdn.microsoft.com/en-us/library/windows/desktop/dd819454.aspx. I’d heartily recommend getting PowerShell v3.0 if you can, if only because of the new ISE.

Source:

Make PowerShell script run cmdlets in global scope by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply