troubleshooting Question

powershell or VB scripts required to carry out over night administration on Exchange Online

Avatar of cybersi
cybersiFlag for United Kingdom of Great Britain and Northern Ireland asked on
PowershellVB ScriptMicrosoft 365Microsoft ExcelMicrosoft Office
7 Comments1 Solution151 ViewsLast Modified:
Hi All

I have a really hard script that I need desperate help on. If anyone can help so that I can schedule to run over night, every night? PS my scripting knowledge is as good as a hamster.

I need help creating a powershell script and or VB scripts for Exchange online to automatically add contacts and add them to a mail enabled group (not public folder or tradition distribution list).

Step one
convert a xlsx file in to a csv files (this xlsx file is created every night probably with a different file name every night).  The cloumns in the cvs will be first name , last name, ExternalEmailAddress, OrganizationUnit.  I will probably have a batch file run to delete any other excel or csv files in this folder before the new xlsx file is created

step two
To be able to run a scheduled powershell to automatically connect to exchange online without any interaction

I got as far as this but it keeps prompting for username and password:

Set-ExecutionPolicy RemoteSigned -Scope Currentuser
$credential = get-credential
Import-Module MSOnline
Connect-MsolService -Credential $credential
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $ExchangeSession

step three
Delete all of my contacts in exchange on line

Step four
Using the converted CSV file automatically import contacts to a exchange group (first name , Last name and email address only).  
If the exchange group does not exist then create a group with the email address (

step five
All of the above will be a scheduled task from the on premises application server.

My bespoke management system is constantly being updated on a daily basis with clients constantly being added and removed from distribution lists.  This is becoming a nightmare to administer so I thought that if I could get my management system to export a report and then use that report to carry out the admin at night time it would save me hours of work each week.

I know its a hard one but I'm sure one or more of you have the knowledge(fingers crossed)

Many thanks

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros