Creating Office 365 Module - cmdlets not available or returned

Hi Guys,

I hope I haven’t missed something elsewhere. I’ve been connecting to office 365 - exchange online with a standard PowerShell script ps1, but felt it would be nice to have the same as a module. So I created a module “Office365Exchange” with two functions “Connect-Office365” and “Disconnect-Office365”. After I connect, I find I can’t run for example get-mailbox, I’ve finally discovered that I can if I run Import-PSSession against the variable I created for the new session "$Global:OfficeSession.

Can anyone tell me why the Import-PSSession in my Process block doesn’t return to the shell? And how I might be able to return it? Otherwise I’m thinking I’ll add:

Write-Warning “Now type Import-PSSession `$Global:OfficeSession”

so that I don’t forget I need to Import the session again. I was really hoping I could do it as a single step.

FYI, I’m running Windows 7 with PowerShell v3 installed.

The session is created in a function and is only in the scope of the function. So, the session only exists while you are in the function. Since you are making the variable Global, it still exists outside the function but it’s just a placeholder of the session, not the session itself.