0
votes

The PowerCli (VMWares powershell module) has a command: Connect-VIServer

You run Connect-VIServer -Server myserver -credentials (get-credentials)

After running that future powercli cmdlets in that session use that connection.

How do I do something like this with my own modules?

I want to have a command I could run like Connect-MyDB -Server mydb -Credentials (get-credentials)

How functions in my module access the server and $credentials variables when I run them in the session?

1

1 Answers

0
votes

You need to define module global variables within psm1 file and not export it afterwards. Alternatively you can use global variable.

As an example you can check out my TFS REST module. It uses global:tfs for connection settings but internally all functions use few variables defined in script _global.ps1 which are dot sourced from withint psm1 file.