Created
May 17, 2022 17:51
-
-
Save mozziemozz/22e54e29fda1304914fecc1b4f73541e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param | |
( | |
[Parameter (Mandatory = $false)] | |
[object] $WebhookData | |
) | |
$uri = "" | |
$Body = (ConvertFrom-Json -InputObject $WebhookData.RequestBody) | |
Write-Output $Body | |
Write-Output $Body.Action | |
$action = ($Body.Action) | |
$Credentials = Get-AutomationPSCredential -Name "AzAutomationAdmin" | |
Connect-MicrosoftTeams -Credential $Credentials | |
$Schedule = Get-CsOnlineSchedule | Where-Object {$_.Name -eq "Manual Override"} | |
switch ($action) { | |
open { | |
$startDate = (Get-Date).addDays(-2).ToString("d/M/yyyy").Replace(".","/") | |
$endDate = (Get-Date).AddDays(-1).ToString("d/M/yyyy").Replace(".","/") | |
$dateTimeRange = New-CsOnlineDateTimeRange -Start $startDate -End $endDate | |
$Schedule.FixedSchedule.DateTimeRanges = $dateTimeRange | |
Set-CsOnlineSchedule -Instance $Schedule | |
} | |
close { | |
$startDate = (Get-Date).addDays(0).ToString("d/M/yyyy").Replace(".","/") | |
$endDate = (Get-Date).AddDays(1).ToString("d/M/yyyy").Replace(".","/") | |
$dateTimeRange = New-CsOnlineDateTimeRange -Start $startDate -End $endDate | |
$Schedule.FixedSchedule.DateTimeRanges = $dateTimeRange | |
Set-CsOnlineSchedule -Instance $Schedule | |
} | |
Default {} | |
} | |
Disconnect-MicrosoftTeams | |
if ($action -eq "open") { | |
$actionFriendly = "opened" | |
} | |
else { | |
$actionFriendly = "closed" | |
} | |
$confirmMessageCard = @' | |
{ | |
"@context": "https://schema.org/extensions", | |
"@type": "MessageCard", | |
"themeColor": "00ff00", | |
"title": "Auto Attendant Updated", | |
"text": "The Auto Attendant has been actionPlaceholder." | |
} | |
'@ | |
$confirmMessageCard = $confirmMessageCard.Replace("actionPlaceholder","$actionFriendly") | |
Invoke-RestMethod -uri $uri -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