I'm trying to use the following function to connect to Office 365 and then run commands outside of the function. If I run the function outside of the function block it works fine, but I keep it in a psm1 and it doesn't allow me to run, for example Get-Mailbox.
Powershell
functionConnect-Exchange365{param()$AESKeyFilePath=**$credentialFilePath=**$passwordSecureString=$Creds.Password$username=**$AESKey=Get-Content$AESKeyFilePath$pwdTxt=Get-Content$credentialFilePath$securePwd=$pwdTxt|ConvertTo-SecureString-Key$AESKey$credObject=New-ObjectSystem.Management.Automation.PSCredential-ArgumentList$username,$securePwd#Opens a Portal the the Exchange Realm$exchangeSession=New-PSSession-ConfigurationNameMicrosoft.Exchange-ConnectionUri**-Credential$credObject-Authentication"Basic"-AllowRedirection...