Forum Discussion
How to get working hours information for all users in a Microsoft 365 organisation
- Jan 18, 2024
Hi, Cezary.
Here's a template based on using the MicrosoftExchangeOnline v3 module.
The template below only outputs people who deviate from the relevant defaults, since there's no value in reporting mailboxes that haven't changed. But you can adjust the filtering criteria as you see fit.
It assumes you have already connected to Exchange Online.
Example
# Frontload the Microsoft mailbox default values to remove unnecessary overhead in the loop later. $DefaultStart = [timespan]::new(8, 0, 0); $DefaultEnd = [timespan]::new(17, 0, 0); # Fetch the working hours of any mailbox that has been changed from the defaults. Get-EXOMailbox -ResultSize unlimited -PropertySets StatisticsSeed -Filter "RecipientTypeDetails -ne 'DiscoveryMailbox'" | ForEach-Object { $CalenderCfg = Get-MailboxCalendarConfiguration -Identity $_.ExchangeGuid -WarningAction:SilentlyContinue; if ( ($CalenderCfg.IsWorkingHoursSectionEnabled) -and ( ($CalenderCfg.WorkDays -eq "Weekdays") -or ($CalenderCfg.WorkingHoursStartTime -ne $DefaultStart) -or ($CalenderCfg.WorkingHoursEndTime -ne $DefaultEnd) ) ) { # Output this non-standard mailbox. [PSCustomObject] @{ id = $_.ExchangeGuid; primarySmtpAddress = $_.PrimarySmtpAddress; workDays = $CalenderCfg.WorkDays; startTime = $CalenderCfg.WorkingHoursStartTime; endTime = $CalenderCfg.WorkingHoursEndTime; timeZone = $CalenderCfg.WorkingHoursTimeZone; } } }Example output
PS: I'm anticipating that you know how to use Export-Csv to pipe the output from the template to a CSV file, so I won't cover that.
Cheers,
Lain
Hi, Cezary.
Here's a template based on using the MicrosoftExchangeOnline v3 module.
The template below only outputs people who deviate from the relevant defaults, since there's no value in reporting mailboxes that haven't changed. But you can adjust the filtering criteria as you see fit.
It assumes you have already connected to Exchange Online.
Example
# Frontload the Microsoft mailbox default values to remove unnecessary overhead in the loop later.
$DefaultStart = [timespan]::new(8, 0, 0);
$DefaultEnd = [timespan]::new(17, 0, 0);
# Fetch the working hours of any mailbox that has been changed from the defaults.
Get-EXOMailbox -ResultSize unlimited -PropertySets StatisticsSeed -Filter "RecipientTypeDetails -ne 'DiscoveryMailbox'" |
ForEach-Object {
$CalenderCfg = Get-MailboxCalendarConfiguration -Identity $_.ExchangeGuid -WarningAction:SilentlyContinue;
if (
($CalenderCfg.IsWorkingHoursSectionEnabled) -and (
($CalenderCfg.WorkDays -eq "Weekdays") -or
($CalenderCfg.WorkingHoursStartTime -ne $DefaultStart) -or
($CalenderCfg.WorkingHoursEndTime -ne $DefaultEnd)
)
)
{
# Output this non-standard mailbox.
[PSCustomObject] @{
id = $_.ExchangeGuid;
primarySmtpAddress = $_.PrimarySmtpAddress;
workDays = $CalenderCfg.WorkDays;
startTime = $CalenderCfg.WorkingHoursStartTime;
endTime = $CalenderCfg.WorkingHoursEndTime;
timeZone = $CalenderCfg.WorkingHoursTimeZone;
}
}
}
Example output
PS: I'm anticipating that you know how to use Export-Csv to pipe the output from the template to a CSV file, so I won't cover that.
Cheers,
Lain