PowerShell Modules – Export-ModuleMember only if plugin is installed!

I have been working to move my scripts to modules. It just occurred to me that I can conditionally Export-ModuleMember if a plugin is installed. For example:

if (Get-PSSnapin -registered -Name "SqlServerProviderSnapin*" -ErrorAction SilentlyContinue) {
Export-ModuleMember Function01,Fuinction02,Function03

Or I could export based on $env:computername. I like that idea. Only this scripts that are supposed to run on that machine are available!

This just occurred to me.


Comments are closed.