Pulling ical (sharing) links from 365 mailboxes

I did this for a dashboard originally, and then also did it to sync my personal calendar to Nextcloud. It is a nice long list of commands but relatively straight forward.

To start a session set your execution policy and provide credentials. The credentials are your full email and password. As far as I can tell, this is a universal section that doesn't need to be modified.

Set-ExecutionPolicy RemoteSigned
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

The next session is where you get your URLs from, you need to substitute email@domain.com and Calendar for your target user and calendar name (Calendar is default). This also generates an HTML link, it is a pretty display.

Import-PSSession $Session
Set-MailboxCalendarFolder email@domain.com:\Calendar -PublishEnabled $true
Set-MailboxCalendarFolder -DetailLevel fulldetail -identity email@domain.com:\Calendar
Get-MailboxCalendarFolder email@domain.com:\Calendar | fl