Created
June 2, 2026 09:12
-
-
Save albertopasqualetto/90763fed6506a7ba07dace067e06a53b to your computer and use it in GitHub Desktop.
Set Teams presence to offline out of office hours
This file contains hidden or 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
| $teams = (Get-Command ms-teams.exe).Source | |
| $offlineCommand = "--set-presence-to-offline" | |
| $resetCommand = "--reset-presence" | |
| $now = Get-Date | |
| # --- night hours → offline --- | |
| $hour = $now.Hour | |
| if ($hour -ge 19 -or $hour -lt 8) { | |
| & $teams $offlineCommand | |
| return | |
| } | |
| # --- weekend → offline --- | |
| $day = $now.DayOfWeek | |
| if ($day -in @("Saturday","Sunday")) { | |
| & $teams $offlineCommand | |
| return | |
| } | |
| # --- holidays → offline --- | |
| $year = $now.Year | |
| $country = "IT" | |
| $holidays = Invoke-RestMethod "https://date.nager.at/api/v3/PublicHolidays/$year/$country" | | |
| Where-Object { $_.counties -eq $null } # only national holidays | |
| $today = $now.ToString("yyyy-MM-dd") | |
| if ($holidays.date -contains $today) { | |
| & $teams $offlineCommand | |
| return | |
| } | |
| # --- default --- | |
| & $teams $resetCommand |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment