Creating Office 365 Module - cmdlets not available or returned

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Rob Simmers Rob Simmers 1 year, 5 months ago.

  • Author
  • #25764
    Profile photo of William Parry
    William Parry

    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.

  • #25766
    Profile photo of Rob Simmers
    Rob Simmers

    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.

You must be logged in to reply to this topic.