Removing Calendar Invites using PowerShell + Azure CLI

Getting around the `This parameter set requires WSMan` error on Mac OS

Apart from my day job, I moonlight helping small-to-medium size companies’ install and manage secure IT infrastructures, along with building and creating applications for them. I offer these services (and more) through my company, Attica, LLC. It is a passion of mine to help companies that are starting out have a solid IT/Cyber infrastructure that can scale with their company as these businesses are vulnerable and common targets of ransomware and phishing attacks. But we can talk more about that later. For now, let’s talk about a recent request I had and how I solved it.

One of the companies I worked with had a recent employee leave, and they wanted to remove the Calendar invites this individual had set up with other employees around the company. They were keeping her account around temporarily so as not to incidentally remove any important information while the transfer occurred, but the calendar invites were becoming an annoyance.

This seemed like an easy enough request, and eventually I found some commands that could be run via PowerShell, such as below. This command is “supposed” to allow you to log into your Active Directory environment to perform some additional commands over a secure connection.

$Session = New-PSSession \
    -ConfigurationName Microsoft.Exchange \
    -ConnectionUri \
    -Credential $cred \
    -Authentication kerberos

Unfortunately, upon running this command, I was hit with the following error:

New-PSSession: This parameter set requires WSMan, and no supported WSMan client library was found. 
WSMan is either not installed or unavailable for this system.

And that’s when the rabbit hole went a little deeper as I uncovered a couple other threads online of people running into issues accessing remote Azure environments using PowerShell on updated Macs. (see reddit and stack overflow which point to this issue on the PowerShell GitHub Page).

These articles indicated that the reason for the above failure is due to the version of OpenSSL that PowerShell has a dependency being different than what is installed on updated Macs, and the solution requires have multiple OpenSSL versions on your system and point to the correct one when performing PowerShell operations.

A lot of the fixes above were lengthy and were really just band-aids vs. permanent solutions, so I thought “Surely there is a better way”.

Enter in Azure CLI.

I won’t go into it now, but I recommend to ALL of my clients to roll with a Cloud service like G-Suite or Azure Active Directory vs. having any kind of in-house setup. It’s better scalable, more secure, and more reliable.

Another great thing, is that it allows you to leverage additional tools like Azure CLI, which are basically a terminal window into your environment, just like what you would have if your servers were in-house you had to remote access them via SSH.

The amazing thing about it here though is it requires NO SETUP! You just log in to your Azure Portal, and literally click a button to open up a terminal (see image below). Credentials are handled because it just uses your current session. BOOM. No unnecessary custom bash scripts to point to various versions of OpenSSL just to make PowerShell behave.

With that, it is literally two commands to remove the calendar invites (or pretty much anything else for that matter).

First, you need to establish an Exchange Online Powershell Session (EXOPSSession). From your Mac, this would typically require a lengthy connection string as seen above where I was having to pass all of my credentials/token/etc to establish a valid session.

For PowerShell, you just type:

PS /home/dustin> Connect-EXOPSSession
Creating implicit remoting module ... [Getting command information from remote session ... 597 commands received   2s]

This command will establish your session, then you just send the command to remove the calendar invites using the Remove-CalendarEvents cmdlet offered through AzureCLI.

It doesn’t get much easier than that.

PS /home/dustin> Remove-CalendarEvents -Identity <email-addres-of-individual> -CancelOrganizedMeetings

And there you have it. It took me a couple of hours to arrive at this solution, but execution of the command above took ~2 minutes. So hopefully this blog will save you 1 hr 58 minutes of your life :)

Have a good day!

comments powered by Disqus