I created a WCF REST service running under IIS to process PowerShell commands. Most of the time the PowerShell script runs successfully without throwing any errors. On occasion though I am seeing the following error message.
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or
DefaultDesktopOnly style to display a notification from a service application.
I suspect this issue occurs when there are concurrent calls to the REST service resulting in simultaneous PowerShell sessions. Following are the commands I execute to establish the PowerShell session. I am not sure if I am missing anything since
this needs to execute non-interactive concurrent sessions.
Set-ExecutionPolicy RemoteSigned
$pw = convertto-securestring -AsPlainText -Force -String "Password"
$cred = new-object -typename PSCredential -argumentlist "Login", $pw
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-MsolService -Credential $cred