Garacesh Posted October 1, 2015 Posted October 1, 2015 (edited) Still can't pin down this O365 script Split my script up into multiple scripts and everything seems to be fine Script 0 - Powershell script to launch the others in sequence Script 1 - Modify email address from @onmicrosoft to @schoolname (Set-MSOLUserPrincipalName) Script 2 - Assign user location to 'GB' (Set-MSOLUser) Script 3 - Remove unused licenses, assign correct ones. (Set-MSOLUser) Script 4 - User role assignment (Set-Mailbox) Script 5 - User retention policy (Set-Mailbox) Script 6 - OWA Policy (Set-CASMailbox) Script 7 - Assign admin permission to access mailbox (Get-Mailbox) Step 6 is where the errors are getting produced once I start trying to assign the Outlook Web App Policy (It took me way too long to figure out what "OWA Policy" meant...) It'll get though however-many users and then bomb, with the error [color="#FF0000"][b]Processing data from remote server ps.outlook.com failed with the following error mesage: WS-Management cannot process the request. The operation failed because of an HTTP error. The HTTP error (12152) is: The server returned an invalid or unrecognized response . For more information, see the about_Remote_Troubleshooting Help topic. [indent] + CategoryInfo : OperationStopped: (ps.outlook.com:String) [], PS RemotingTransportException + FullyQualifiedErrorId : JobFailure + PSComputerName : ps.outlook.com[/b][/color][/indent] It tries to do the next user, bombs again with the same error message, for a seemingly random number of tries (I've observed once and four times) then finally bombs out permanently, this time with: [b][color="#FF0000"][ps.outlook.com] Processing data from remote server ps.outlook.com failed with the following error mesage: WS-Management cannot process the request. The operation failed because of an HTTP error. The HTTP error (12152) is: The server returned an invalid or unrecognized response . For more information, see the about_Remote_Troubleshooting Help topic. [indent] + CategoryInfo : OpenError: (ps.outlook.com:String) [], PSRemotin gTransportException + FullyQualifiedErrorId : JWinRMOperationAborted,PSSessionStateBroken[/color][/b][/indent] It then seems to do the next user just fine, and then the next user it stalls, throws "Creating a new session for implicit remoting of "Set-CASMailbox" command..." and asks for credentials again, then just carries on as normal. Then a little further down the line it bombs out again, same errors. Input credentials, carries on normally. The accounts it dies on seem to have no correlation to each other, it works for staff and kids across all ages and has failed on staff and kids, too. The actual code being run is just a simple foreach loop with 2 if statements. # Assign Outlook Web App policy if ($PupilList -contains ($User -replace "@[i][/i]schoolname", "")) { # If account is a pupil account Set-CASMailbox -Identity $User -OWAEnabled $true -OwaMailboxPolicy "Student OWA Policy" # Apply student OWA Policy } if ($StaffList -contains ($User -replace "@[i][/i]schoolname", "")) { # If account is a pupil account Set-CASMailbox -Identity $User -OWAEnabled $true -OwaMailboxPolicy "Staff OWA Policy" # Apply staff OWA Policy } } Edit: Yay, more errors thrown now [b][color="#FF0000"]Starting a command on remote server failed wit hthe following error message : The I/O operation has been aborted because of either a thread exit or an application request. For more information, see the about_Remote_Troubleshooting Help topic. [indent] + CategoryInfo : OpenError: (ps.outlook.com:String) [], PSRemotin gTransportException + FullyQualifiedErrorId : JWinRMOperationAborted,PSSessionStateBroken[/color][/b][/indent] [b][color="#FF0000"][ps.outlook.com] Processing data from remote server ps.outlook.com failed with the following error mesage: WS-Management cannot process the request. The operation failed because of an HTTP error. The HTTP error (12152) is: The server returned an invalid or unrecognized response . For more information, see the about_Remote_Troubleshooting Help topic. [indent] + CategoryInfo : OpenError: (ps.outlook.com:String) [], PSRemotin gTransportException + FullyQualifiedErrorId : JWinRMOperationAborted,PSSessionStateBroken[/indent] Cannot invoke pipeline because runspace is not i nthe Opened state. Current state of runspace is 'Broken'. [indent] + CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRuns pace:ExecutionCmdletHelperRunspace) [], InvalidRunspaceStateException + FullyQualifiedErrorId : InvalidSessionState,System.Management.Automation[/color][/b][/indent] Edited October 1, 2015 by Garacesh
Boredguy Posted October 1, 2015 Posted October 1, 2015 We found that if we added a sleep for 60 seconds after creating/assigning Exchange licence then updated their mailbox policies it worked ok.
Garacesh Posted October 1, 2015 Author Posted October 1, 2015 There's definitely more than a 60 second delay between the Licensing script ending and the Mailbox policy script beginning. Originally these were all run as one big script so it would do UserA's email, location, license, etc then UserB's email, location, etc. but that was throwing similar errors and making me re-authenticate every 2 minutes, so I split them up to try and figure out where it was going wrong. It's also doing the same kind of errors with Get-Mailbox now. I'm wondering is there a maximum session time..? But each script creates and removes their own PSSession so I don't think it would be that..
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now