Skip to content

Instantly share code, notes, and snippets.

@mozziemozz
Last active September 6, 2022 21:05
Show Gist options
  • Select an option

  • Save mozziemozz/d871770b0f9c477d765f5ff2f391c03e to your computer and use it in GitHub Desktop.

Select an option

Save mozziemozz/d871770b0f9c477d765f5ff2f391c03e to your computer and use it in GitHub Desktop.
param
(
[Parameter (Mandatory = $false)]
[object] $WebhookData
)
$teamsWebhookUrl = ""
$Body = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)
Write-Output $Body
# Initialize Variables
$scheduleId = $Body.scheduleId
$oldStartDate = $Body.oldStartDate
$oldEndDate = $Body.oldEndDate
$newStartDate = $Body.newStartDate
$newEndDate = $Body.newEndDate
$Credentials = Get-AutomationPSCredential -Name "AzAutomationAdmin"
Connect-MicrosoftTeams -Credential $Credentials
$schedule = Get-CsOnlineSchedule -Id $scheduleId
$matchingOldDateTimeRange = $schedule.FixedSchedule.DateTimeRanges | Where-Object {$_.Start -eq $oldStartDate -and $_.End -eq $oldEndDate}
$schedule.FixedSchedule.DateTimeRanges = $schedule.FixedSchedule.DateTimeRanges | Where-Object {$_ -notcontains $matchingOldDateTimeRange}
$newDateTimeRange = New-CsOnlineDateTimeRange -Start $newStartDate -End $newEndDate
$schedule.FixedSchedule.DateTimeRanges += $newDateTimeRange
Set-CsOnlineSchedule -Instance $schedule
Disconnect-MicrosoftTeams
$confirmMessageCard = @"
{
"@context": "https://schema.org/extensions",
"@type": "MessageCard",
"themeColor": "7FBA00",
"title": "Holiday Schedule Updated",
"text": "Holiday Schedule Name: **$($schedule.Name)**<br>Old start and end date: **$oldStartDate** - **$oldEndDate**<br>New start and end date: **$($newDateTimeRange.Start)** - **$($newDateTimeRange.End)**"
}
"@
Invoke-RestMethod -uri $teamsWebhookUrl -Method Post -body $confirmMessageCard -ContentType 'application/json; charset=UTF-8'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment