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