suDoublebookRooms.ps1

<#PSScriptInfo
 
.VERSION 1.0
 
.GUID c7eefced-986e-42fe-97d9-67ba2bc575ce
 
.AUTHOR info@sumatra.com
 
.COMPANYNAME Sumatra Development LLC
 
.COPYRIGHT 2017-2022 Sumatra Development LLC. All rights reserved.
 
.TAGS DoubleBook Resources Rooms
 
.LICENSEURI
 
.PROJECTURI https://sumatra.com/
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES suDoubleBookedMeetings.dll,Microsoft.Exchange.WebServices.dll,Microsoft.Identity.Client.dll, Microsoft.IdentityModel.Abstractions.dll
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES 2022_suDblBook_app_creation
 
.RELEASENOTES
Sumatra's cmdlet now supports the following features:
REPORTING on double-booked resources via CSV or HTML.
NOTIFYING meeting organizers of double-booked resources.
ACTING optionally to cancel double-booked meetings based on conditions.
UPDATED for Modern Authentication.
TEMPLATES for reading from file list or Active Directory.
 
.PRIVATEDATA
 
#>


#Requires -Module Microsoft.IdentityModel.Abstractions.dll
#Requires -Module Microsoft.Exchange.WebServices.dll
#Requires -Module Microsoft.Identity.Client.dll
#Requires -Module @{ModuleVersion = '4.47.1'; ModuleName = 'Microsoft.Identity.Client.dll'}
#Requires -Module suDoubleBookedMeetings.dll

<#
 
.DESCRIPTION
 A set of scripts to invoke our Double-Booking cmdlet to report or notify of double-booked resources.
 
#>
 
Param()


# Copyright(C) 2015-2022 Sumatra Development LLC
# Script Version Date: October 11, 2022
#
#This is a SAMPLE of the PowerShell commands to install and run the Sumatra Double-Booking cmdlet
#
#In general you will want to put together a few PowerShell scripts that can accomplish your desired goals
#and execute them on a convenient schedule for your organization.
#
#The examples here should go a long way towards helping you accomplish that.
#
#
#WHY Use the Sumatra Double-Booking cmdlet?
#
#It REPORTS double-booked resources to a CSV or HTML file
#It NOTIFIES organizers of conflicts so they can work it out.
#It allows you to ACT by automatically cancelling some organizers based on your criteria.
#It leaves all this IN YOUR CONTROL.
#
#Currently the Double-Booking cmdlet is licensed from Sumatra Development
#for US $500 for one year per domain with up to 50 resources.
#
#Need to contact us: https://sumatra.com or info@sumatra.com
#
#Much information is also available on our blog: https://calendarservermigration.blogspot.com/
#
#Assumes PowerShell 7.0.
#Run PowerShell as administrator!!
#
#Before this you will need to register the cmdlet on your Office 365 tenant.
#You can accomplish this via a script or via the Admin interface in Office 365.
#See our documentation and the PowerShell script we provide for that.
#2022_suDblBook_app_creation.PS
#
#This is a .TXT file. When you have it working as you want rename to a .PS file to execute in PowerShell.
#On the PowerShell repository it has been renamed as a .PS file already.
#
#
# Some Variables used to connect to O365 and operate the cmdlet
#
$mux="ADMIN@COMPANY.onmicrosoft.com"
$mpx=ConvertTo-SecureString -string "PASSWORD" -AsPlainText -force
$myCreds =  new-object -typename System.Management.Automation.PSCredential -argumentlist $mux,$mpx
$myRoom = "room222@COMPANY.onmicrosoft.com"
$myPath="C:\Users\ADMIN\Desktop\suDoubleBookedMeetings"
$myTenantID="73fe0a2a-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
$myCliID="72cbe6cc-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
$mySecret="esvVXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

#DOUBLE BOOKED MEETING Directory -- this command changes to that directory.
cd $myPath
C:

#change command prompt to suDblBk: Just to make things shorter / simpler.
function prompt { 
'suDblBk ' + ($pwd -split '\\')[0]+' '+$(($pwd -split '\\')[-1] -join '\') + '> '
}

set-executionpolicy unrestricted

#PowerShell 7 requires an older version of the Microsoft Identity Client DLLg
#Using Windows PowerShell 5 this step is unnecessary.
#We KNOW we told you to use PowerShell 7 but experience shows you can work this in PowerShell 5
if((get-module|Where-Object {$_.Name -like "Identity.Client"}|Measure-Object).Count -eq 0)
{
    Import-Module .\Microsoft.Identity.Client.dll
}


# Requires Exchange Online Management version 3.0; Only has to be imported once -- it's commented out
# Install-Module -Name ExchangeOnlineManagement -force

#Import ExchangeOnline
$error.clear
if (!(get-module|Where-Object {$_.Name -eq "ExchangeOnlineManagement"}))
{
    try {
        Import-Module ExchangeOnlineManagement
        write-debug 'Importing ExchangeOnlineManagement'
    }
    catch{
        Install-Module -Name ExchangeOnlineManagement -force 
        Import-Module ExchangeOnlineManagement
        write-debug 'Installing AND Importing ExchangeOnlineManagement'
    }
}

#Connect to Exchange
#--------------------
Connect-ExchangeOnline -UserPrincipalName $mux -ShowBanner:$false -Credential $myCreds

# Note, Use Delegate if Sumatra Manages your environment [-ExchangeEnvironmentName <Value>] [-DelegatedOrganization <String>] [-PSSessionOption $ProxyOptions]
# You will be prompted for cred if you don't pass in -credential


# Bring in the double booking DLL
if((get-module|Where-Object {$_.Name -like "suDoubleBookedMeetings"}|Measure-Object).Count -eq 0)
{
    import-module .\suDoubleBookedMeetings.dll â€“verbose
}

#This is a sample command to report on double-booked meetings in an HTML.
#Note the back tick -- it's a line continuation
Get-suDoubleBookedMeetings `
 -writeHTML  `
 -HTMLFile ($myPath + "\MyHtml.html") `
 -ExchangeVersion 2013   `
 -EWSurl "https://outlook.office365.com/EWS/Exchange.ASMX"   `
 -PrimarySMTPAddress $myRoom   `
 -ImpersonationAccount $mux `
 -Credential $myCreds `
 -bw 30   `
 -ApplicationTenantID "$myTenantID" `
 -ApplicationClientID "$myCliID" `
 -ApplicationSecretID "$mySecret" `
 -licensefile ($myPath + "\license.txt") `
 -Verbose  -confirm:$false

#This is a sample command to email users to inform of double-bookings.
#Note the back tick -- it's a line continuation
Get-suDoubleBookedMeetings `
 -EmailMessageFileName ($myPath + "\messages.txt")  `
 -EmailOrganizers `
 -HTMLFile ($myPath + "\MyHtml.html") `
 -ExchangeVersion 2013   `
 -EWSurl "https://outlook.office365.com/EWS/Exchange.ASMX"   `
 -PrimarySMTPAddress $myRoom   `
 -ImpersonationAccount $mux `
 -Credential $myCreds `
 -bw 30   `
 -ApplicationTenantID "$myTenantID" `
 -ApplicationClientID "$myCliID" `
 -ApplicationSecretID "$mySecret" `
 -licensefile ($myPath + "\license.txt") `
 -Verbose  -confirm:$false

#Read a list of resources from a text file and run the cmdlet on them.
#Basic structure:
# get-content rooms.txt | foreach {COMMAND ABOVE}
# BUT $_ takes place of -PrimarySMTPAddress $myRoom
#
#

get-content rooms.txt | foreach {suDoubleBookedMeetings   $_ -Credentials $myCreds  `
   -BookingWindow: 30 -EwsUrl "https://outlook.office365.com/EWS/Exchange.ASMX" `
    -CsvFile ($MyPath + "\mycccsv.csv") -ApplicationTenantID "$myTenantID" `
   -ApplicationClientID "$myCliID" `
   -ApplicationSecretID "$mySecret" `
   -licensefile ($myPath + "\license.txt") `
}


#From Get-Mailbox
Get-Mailbox -filter {isResource -eq $true} -resultsize unlimited |Select-Object PrimarySMTPAddress | `
suDoubleBookedMeetings  -Credentials $myCreds  `
   -BookingWindow: 10 -EwsUrl "https://outlook.office365.com/EWS/Exchange.ASMX" `
   -CsvFile ($MyPath + "\mycccsv.csv") `
   -ApplicationTenantID "$myTenantID" `
   -ApplicationClientID "$myCliID" `
   -ApplicationSecretID "$mySecret" `
   -licensefile ($myPath + "\license.txt") 


#Get Help
Get-Help Get-suDoubleBookedMeetings


#Optional Switches NOT USED in the above example
#-VIPsGetBookingPreference `
#-DeclineConflicts `
#-VIPFile ($myPath + "\vips.txt") `
#
#Why do we not include these examples?
#Best practice on this is to start as light and unintrusive as you can and then ratchet up.
#Warning organizers of conflicts should be enough to get them to work it out.
#If not the manual contains more explicit examples.

#When done:
Disconnect-ExchangeOnline


#########################################################################################################

#For the VERY technical.
#The Sumatra cmdlet requires version 4.47.1 of Microsoft.Identity.Client.dll
#PowerShell 7 defaults to version 4.41 While PowerShell 5 runs with both versions, version 7 is not so liberal.
#
#This command in PowerShell will expose your installed DLLs WITH Version numbers. Good for checking / maintenance.
[System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location | Sort-Object -Property FullName | Select-Object -Property FullName, Location, GlobalAssemblyCache, IsFullyTrusted | Out-GridView