Skip to content

Commit c836ef6

Browse files
committed
Add Set-CIPPAlwaysShowFrom function
1 parent 3aa543f commit c836ef6

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
Function Set-CIPPAlwaysShowFrom {
3+
<#
4+
.SYNOPSIS
5+
Sets the "Always Show From" property for a user or all users in a tenant.
6+
7+
.DESCRIPTION
8+
The Set-CIPPAlwaysShowFrom function is used to set the "Always Show From" property for a specified user or all users in a specified tenant. The "Always Show From" property determines whether the from field is always shown in Outlook.
9+
10+
.PARAMETER UserID
11+
Specifies the user ID for which to set the "Always Show From" property. This parameter is mandatory unless the RunOnAllUsersInTenant switch is used.
12+
13+
.PARAMETER TenantFilter
14+
Specifies the tenant for which to set the "Always Show From" property.
15+
16+
.PARAMETER APIName
17+
Specifies the name of the API. The default value is "Always Show From".
18+
19+
.PARAMETER ExecutingUser
20+
Specifies the user who is executing the function.
21+
22+
.PARAMETER AlwaysShowFrom
23+
Specifies whether to set the "Always Show From" property to true or false.
24+
25+
.PARAMETER RunOnAllUsersInTenant
26+
If this switch is present, the function will set the "Always Show From" property for all users in the specified tenant.
27+
28+
.EXAMPLE
29+
Set-CIPPAlwaysShowFrom -UserID "john.doe@example.com" -TenantFilter "example.com" -AlwaysShowFrom $true
30+
Sets the "Always Show From" property to true for the user "john.doe@example.com" in the "example.com" tenant.
31+
32+
.EXAMPLE
33+
Set-CIPPAlwaysShowFrom -TenantFilter "example.com" -AlwaysShowFrom $true -RunOnAllUsersInTenant
34+
Sets the "Always Show From" property to true for all users in the "example.com" tenant.
35+
#>
36+
[CmdletBinding(DefaultParameterSetName = 'User')]
37+
param (
38+
[Parameter(Mandatory = $true, ParameterSetName = 'User')]
39+
[Parameter(Mandatory = $false, ParameterSetName = 'AllUsers')]
40+
[Alias('Username')][string]$UserID,
41+
42+
[Parameter(Mandatory = $true, ParameterSetName = 'User')]
43+
[Parameter(Mandatory = $true, ParameterSetName = 'AllUsers')]
44+
$TenantFilter,
45+
46+
[Parameter(ParameterSetName = 'User')]
47+
[Parameter(ParameterSetName = 'AllUsers')]
48+
$APIName = 'Always Show From',
49+
50+
[Parameter(ParameterSetName = 'User')]
51+
[Parameter(ParameterSetName = 'AllUsers')]
52+
$ExecutingUser,
53+
54+
[Parameter(Mandatory = $true, ParameterSetName = 'User')]
55+
[Parameter(Mandatory = $true, ParameterSetName = 'AllUsers')]
56+
[bool]$AlwaysShowFrom,
57+
58+
[Parameter(ParameterSetName = 'AllUsers')]
59+
[switch]$RunOnAllUsersInTenant
60+
)
61+
62+
63+
if ($RunOnAllUsersInTenant.IsPresent -eq $true) {
64+
$AllUsers = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-Mailbox' -cmdParams @{ ResultSize = 'Unlimited' }
65+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Setting Always Show From to $AlwaysShowFrom for all $($AllUsers.Count) users in $TenantFilter" -Sev 'Info' -tenant $TenantFilter
66+
$ErrorCount = 0
67+
foreach ($User in $AllUsers) {
68+
try {
69+
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-MailboxMessageConfiguration' -anchor $User.UserPrincipalName -cmdParams @{AlwaysShowFrom = $AlwaysShowFrom; Identity = $User.UserPrincipalName }
70+
Write-Host "Set Always Show From to $AlwaysShowFrom for $($User.UserPrincipalName)"
71+
} catch {
72+
$ErrorCount++
73+
}
74+
}
75+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Set Always Show From to $AlwaysShowFrom for $($AllUsers.Count - $ErrorCount) users in $TenantFilter" -Sev 'Info' -tenant $TenantFilter
76+
return "Set Always Show From to $AlwaysShowFrom for $($AllUsers.Count - $ErrorCount) users in $TenantFilter"
77+
} else {
78+
try {
79+
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-MailboxMessageConfiguration' -anchor $UserID -cmdParams @{AlwaysShowFrom = $AlwaysShowFrom; Identity = $UserID }
80+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Set Always Show From to $AlwaysShowFrom for $UserID" -Sev 'Info' -tenant $TenantFilter
81+
} catch {
82+
$ErrorMessage = Get-CippException -Exception $_
83+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not set Always Show From to $AlwaysShowFrom for $UserID. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
84+
return "Could not set Always Show From to $AlwaysShowFrom for $UserID. Error: $($ErrorMessage.NormalizedError)"
85+
}
86+
return "Set Always Show From to $AlwaysShowFrom for $UserID"
87+
}
88+
}

0 commit comments

Comments
 (0)