Skip to content

Instantly share code, notes, and snippets.

@albertopasqualetto
Created June 2, 2026 09:12
Show Gist options
  • Select an option

  • Save albertopasqualetto/90763fed6506a7ba07dace067e06a53b to your computer and use it in GitHub Desktop.

Select an option

Save albertopasqualetto/90763fed6506a7ba07dace067e06a53b to your computer and use it in GitHub Desktop.
Set Teams presence to offline out of office hours
$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