

{"id":517,"date":"2022-07-26T13:48:38","date_gmt":"2022-07-26T11:48:38","guid":{"rendered":"https:\/\/blog.koeckeis-fresel.net\/?p=517"},"modified":"2024-03-16T07:25:20","modified_gmt":"2024-03-16T06:25:20","slug":"o365-enable-save-in-mailbox-for-delegates","status":"publish","type":"post","link":"https:\/\/blog.koeckeis-fresel.net\/?p=517","title":{"rendered":"O365 &#8211; enable save in mailbox for delegates"},"content":{"rendered":"\n<p>See <a href=\"https:\/\/docs.microsoft.com\/en-us\/exchange\/troubleshoot\/user-and-shared-mailboxes\/sent-mail-is-not-saved\">https:\/\/docs.microsoft.com\/en-us\/exchange\/troubleshoot\/user-and-shared-mailboxes\/sent-mail-is-not-saved<\/a><\/p>\n\n\n\n<p>Connect to Exchange-Online (Office 365) and set mailbox-features for single mailbox with option to update all mailboxes<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Set execution policy for this process only\nSet-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned\n\n# Define variables\n$UserPrincipalName = \"admin@example.onmicrosoft.com\"\n$Mailbox = \"office@example.com\"\n$RunForAllMailboxes = \"N\" # Default value\n\n# Function to check and log mailbox actions\nFunction Log-MailboxAction {\n    Param (\n        &#91;string]$LogPath,\n        &#91;string]$Message\n    )\n    if (!(Test-Path $LogPath)) {\n        New-Item -ItemType Directory -Path $LogPath -Force\n    }\n    Add-Content -Path \"$LogPath\\${FQDN}_mailbox_set_sent_on_behalf.log\" -Value $Message\n}\n\n# Validate UserPrincipalName and Mailbox\nif ($UserPrincipalName -eq \"admin@example.onmicrosoft.com\" -or $Mailbox -eq \"office@example.com\") {\n    Write-Error \"Error 500 - you are using the variables from the template. Edit them before using :)\"\n    Start-Sleep -Seconds 60\n    exit\n}\n\n# Determine FQDN from UserPrincipalName for logging\n$FQDN = $UserPrincipalName.Split('@')&#91;1]\n$LogPath = \"C:\\temp\"\n\n# Check if ExchangeOnlineManagement module is installed\nif (-not (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) {\n    Install-Module -Name ExchangeOnlineManagement\n} else {\n    Update-Module -Name ExchangeOnlineManagement\n}\n\nImport-Module ExchangeOnlineManagement\nConnect-ExchangeOnline -UserPrincipalName $UserPrincipalName\n\nif ($RunForAllMailboxes -eq \"Y\") {\n    # Log and update all mailboxes\n    Get-Mailbox | Where-Object { $_.MessageCopyForSentAsEnabled -eq $null } | ForEach-Object {\n        Set-Mailbox -Identity $_.Identity -MessageCopyForSendOnBehalfEnabled $true -MessageCopyForSentAsEnabled $true\n        Log-MailboxAction -LogPath $LogPath -Message \"Updated: $($_.Identity)\"\n    }\n} else {\n    # Check if single mailbox is valid\n    $validMailbox = Get-Mailbox -Identity $Mailbox -ErrorAction SilentlyContinue\n    if ($null -eq $validMailbox) {\n        Write-Error \"Error 500 - Not a valid mailbox\"\n        Start-Sleep -Seconds 60\n        exit\n    } else {\n        Set-Mailbox -Identity $Mailbox -MessageCopyForSendOnBehalfEnabled $true -MessageCopyForSentAsEnabled $true\n        Log-MailboxAction -LogPath $LogPath -Message \"Updated: $Mailbox\"\n    }\n}\n\nDisconnect-ExchangeOnline\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>See https:\/\/docs.microsoft.com\/en-us\/exchange\/troubleshoot\/user-and-shared-mailboxes\/sent-mail-is-not-saved Connect to Exchange-Online (Office 365) and set mailbox-features for single mailbox with option to update all mailboxes<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,38,14],"tags":[23,24,37],"class_list":["post-517","post","type-post","status-publish","format-standard","hentry","category-mail","category-office365","category-powershell","tag-exchange","tag-mail","tag-office365"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/blog.koeckeis-fresel.net\/index.php?rest_route=\/wp\/v2\/posts\/517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.koeckeis-fresel.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.koeckeis-fresel.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.koeckeis-fresel.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.koeckeis-fresel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=517"}],"version-history":[{"count":0,"href":"https:\/\/blog.koeckeis-fresel.net\/index.php?rest_route=\/wp\/v2\/posts\/517\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.koeckeis-fresel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.koeckeis-fresel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.koeckeis-fresel.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}