I'm trying to create a Function on my module that will create a PsSession and to import it to my console. The script block itself is ok, but after running the cmdlet, I cannot import the PsSession although the function imports it.
Function ConnectTo-Office365 {
[cmdletbinding()]
$365Credential = Get-Credential -Message "Office365 Credentials";
$365Session = New-PSSession -ConfigurationName Microsoft.Exchange ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $365Credential -Authentication Basic -AllowRedirection;
Import-PSSession $365Session}
I've read on Global Variables but could not understand how to use it to my purpose.
Thanks!