I would like to run powershell exchange scripts on the mid server. How would I go about doing this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 02:37 PM
I would like to be able to write a step in my mid server script file to login to exchange online (Connect-ExchangeOnline) and run a simple line of powershell.
ie Add-MailboxFolderPermission -Identity john.doe@123.com ...........
From what I can tell, in the mid server script file, I would need a line of code to login to powershell exchange and then a line of code to run the above command. The following post shows one way to run powershell exchange commands on the mid-server but was hoping there was a less tedious way of accomplishing this:
https://community.servicenow.com/community?id=community_question&sys_id=3e9d0f2ddb9cdbc01dcaf3231f9619f9
- Labels:
-
MID Server

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 03:24 PM
Hi,
The following steps using Orchestration activity pack (different license required) seems to be doing something similar.
Following thread has a sample not using Orchestration activity pack. It's not using credentials in the script but it credentials can be hardcoded into the script, it offers a simpler solution.
If the question is about writing a powershell script to connect to exchange and retrieve information, it's probably better to post the question to MS's exchange forum instead of to the ServiceNow forum.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 03:55 PM
I have previous used the John J Anderson Powershell utility and it worked great. Michel Conter went and updated it since, and has provided the update set in his post.
https://community.servicenow.com/community?id=community_question&sys_id=7fda0f6ddb5cdbc01dcaf3231f96197c
I think this will lead you down the path to what you're looking for. I find it an easy way to avoid RDP'ing into servers to execute Powershell commands (I hope my IT Security team doesn't read this lol).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 02:21 PM
Thanks both!
So instead of simply logging into the midserver account, SNOW would use the same midserver account credentials to login to the powershell exchange module and run a command. With that said I am open to suggestions.
ex.
I would create a connection and credential alias in ServiceNow for the exchange admin login that I could store in a variable such as $psCred in the bold text below and access in the midserver script file.
MidServer script file would then execute the following:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/-Credential $psCred -Authentication Basic -AllowRedirection;
$result = Import-PSSession $Session -AllowClobber -DisableNameChecking Add-MailboxFolderPermission -Identity jake.doe@microsoft:\Contacts -user josh.doe@microsoft.com -AccessRights Editor Credential $cred -Server $computer;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2022 12:02 PM
Did you ever get this working? Looking to do the same thing but we have the added obstacle of MFA.