Hello all! I recently solved an issue but I don’t know why the solution worked, so I am seeking some guidance. I am working on creating a PowerShell module with various Skype for Business Online functions. One of them is creating a remote PowerShell connection out to Skype for Business Online. Here is a shortened example of the code:
function Connect-SkypeOnline { $credentials = Get-Credential $SkypeSession = New-CsOnlineSession -Credential $credentials Import-PSSession -Session $SkypeSession -AllowClobber }
After importing the module with this function, I would run the command successfully and the remote PowerShell session would be created, however, the module with all the commands would not be imported. However, if I copy/pasted the function code directly into the PowerShell window, the Connect-SkypeOnline function would work as expected and the module would be there. I found the solution here with someone doing the same thing except with Exchange Online PowerShell. Here is the working code:
function Connect-SkypeOnline { $credentials = Get-Credential $SkypeSession = New-CsOnlineSession -Credential $credentials Import-Module (Import-PSSession -Session $SkypeSession -AllowClobber) -Global }
My question is why do I have to use Import-Module -Global to make the module available outside of the my custom module?