UpdateWorkDays.psm1 is a PowerShell script to update Exchange Server mailbox calendar's "WorkDays" property.
It defines functions Update-WorkDays and Get-Token.
When you use Exchange Server's cmdlet to configure WorkDays to either "Weekdays" or "AllDays", Outlook does not understand these literal values.
e.g.
Set-MailboxCalendarConfiguration user01 -WorkDays AllDays As a result, the calendar looks "grayed-out".
This script fixes this situation by modifying the WorkDays value as follows:
- if "AllDays" --> "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
- if "Weekdays" --> "Monday Tuesday Wednesday Thursday Friday"
- PowerShell v3 or later
- .NET Framework 4.6.1 or later
The following modules need to be placed under "modules" sub folder where the script file is. These are included in the release package.
-
With Exchange Management Shell, grant ApplicationImpersonation role to a user who runs the script
This script uses EWS Impersonation to access the target mailbox.
e.g.
New-ManagementRoleAssignment -Role 'ApplicationImpersonation' -User contoso\administrator
-
Start PowerShell and Import-Module the script
e.g.
Import-Module 'C:\tmp\UpdateWorkDays.psm1'
-
If you are using Modern Auth, get a token
You can use
Get-Tokenincluded in this script.e.g.
$token = Get-Token -ClientId '63ce5cc6-c944-4baa-83d1-5cac8cdf487e' -Scopes 'https://outlook.office365.com/EWS.AccessAsUser.All'
* Client ID above is just an example. Use your own application's Client ID.
-
Execute Update-WorkDays
name meaning Server Name of the Exchange server. For Exchange Online, outlook.office365.comTargetMailboxSmtpAddress Target mailbox whose WorkDays you are trying to fix * These parameters are mutually exclusive:
Credentialfor legacy auth andTokenfor Modern auth.name meaning Credential Credential used for Legacy auth Token Access token used for Modern auth name meaning EwsManagedApiPath Path to Microsoft.Exchange.WebServices.dll EnableTrace Switch parameter to enable tracing TraceFile Path to a trace file e.g.
Update-WorkDays -Server 'myExchange.contoso.local' -TargetMailboxSmtpAddress 'user01@contoso.local' -Credential (Get-Credential) -EnableTrace -TraceFile 'C:\temp\trace.txt'
e.g.
* The following Client ID is just an example. Use your own application's Client ID.
* If your application is registered as a muti-tenant app, then you do not need to provideTenantIdparameter forGet-Token(Just as this example). If your application is a single-tenant app, then specify the tenant name or GUID inTenantId.$token = Get-Token -ClientId '63ce5cc6-c944-4baa-83d1-5cac8cdf487e' -Scopes 'https://outlook.office365.com/EWS.AccessAsUser.All' Update-WorkDays -Server 'outlook.office365.com' -TargetMailboxSmtpAddress 'user01@contoso.com' -Token $token.AccessToken -EnableTrace -TraceFile 'C:\temp\trace.txt'
If you are using Modern Auth, then you first need to register an application in your Azure AD.
Get-Tokenuseshttps://login.microsoftonline.com/common/oauth2/nativeclientas the default Redirect URI. If your application uses a different URI, provide it toRedirectUri.- For API Permissions, add
Exchange'sEWS.AccessAsUser.All
Copyright (c) 2020 Ryusuke Fujita
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.