I have a PowerShell script/function that works great when I use it in my PowerShell profile or manually copy/paste the function in the PowerShell window.
I'm trying to make the function accessible to other members of my team as a module. I want to have the module stored in a central place so we can all add it to our PSModulePath.
Here is a copy of the basic function:
Function Connect-O365{ $o365cred = Get-Credential username@domain.onmicrosoft.com $session365 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUrihttps://ps.outlook.com/powershell/ -Credential $o365cred -Authentication Basic -AllowRedirection Import-PSSession $session365 -AllowClobber }
If I save this function in my PowerShell profile it works fine. I can dot source a *.ps1 script with this function in it and it works as well.
The issue is when I save the function as a *.psm1 PowerShell script module. The function runs fine but none of the exported commands from the Import-PSSession are available. I think this may have something to do with the module scope.
I'm looking for suggestions on how to get around this.
I've posted this on www.stackoverflow.com as well but unfortunately haven't had any luck finding a solution.