Issue with trying to Connect to Exchange Online

I’m trying to create a dashboard to create shared mailboxes in Exchange Online (Office 365). I’m using a New-UDInput to get the information on the mailbox. Works great. I have no issue creating the local AD account, and can even remotely start the AD Sync to the cloud (yes, we’re hybrid). The issue I’m running into is when I attempt to create a session to Exchange online.

I’m on the latest version of Dashboard (I just discovered the product on Thursday!)

Here is my code (within the Endpoint of a New-UDInput). Any assistance would be appreciated.

$O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Cache:O365Cred -Authentication Basic -AllowRedirection

Import-PSSession $O365Session -CommandName Set-Mailbox -DisableNameChecking -AllowClobber

In the debug, I keep seeing this:

09:51:54 [Warn] ComponentController RunScript() Self referencing loop detected for property ‘Module’ with type ‘System.Management.Automation.PSModuleInfo’. Path ‘[3].ExportedFunctions.Set-Mailbox’.
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
at UniversalDashboard.Controllers.ComponentController.ConvertToActionResult(Object result)
at UniversalDashboard.Controllers.ComponentController.<>c__DisplayClass7_1.b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at UniversalDashboard.Controllers.ComponentController.d__7.MoveNext()
09:51:54 [Info] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker Executed action UniversalDashboard.Controllers.ComponentController.Input (UniversalDashboard) in 141674.452ms
09:51:54 [Error] Microsoft.AspNetCore.Server.Kestrel Connection id “0HLPOBH560CCD”, Request id “0HLPOBH560CCD:00000004”: An unhandled exception was thrown by the application.

Thank you!

Are you returning something from the endpoint? It looks like it’s trying to serialize something and running into the self-referencing loop. Like, does Import-PSSession return something? Maybe try to pipe that out Out-Null.

That did the trick! Thank you. Silly me for not thinking of that.