{"id":916,"date":"2012-02-03T11:05:54","date_gmt":"2012-02-03T11:05:54","guid":{"rendered":"http:\/\/www.edwardsd.co.uk\/work\/?p=916"},"modified":"2021-07-05T11:47:16","modified_gmt":"2021-07-05T10:47:16","slug":"office-365","status":"publish","type":"post","link":"https:\/\/www.edwardsd.co.uk\/work\/2012\/02\/office-365\/","title":{"rendered":"Office 365 | Powershell"},"content":{"rendered":"<p>With the migration of many BPOS accounts to Office 365 there have been some major changes to the back-end resulting in a different method connecting via PowerShell in order to use command line syntax.<\/p>\n<p>To use the PowerShell command line syntax for Office 365 you first need to initiate a connection to the 365 servers:<\/p>\n<p><strong>Powershell using &#8220;Microsoft Online Services Module for Windows PowerShell&#8221;<\/strong><\/p>\n<p>You may experience the following error when running Powershell Commands:<\/p>\n<p><em>&#8220;File cannot be loaded because the execution of scripts is disabled on this system&#8221;<\/em><\/p>\n<p>You can run this command to remove the execution restriction.<\/p>\n<pre lang=\"powershell\">Set-ExecutionPolicy Unrestricted<\/pre>\n<p><strong><!--more-->Open Connection:<\/strong><\/p>\n<pre lang=\"powershell\">$LiveCred = Get-Credential<\/pre>\n<p><strong>Enter admin credentials for required domain:<\/strong><\/p>\n<pre lang=\"powershell\">$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https:\/\/ps.outlook.com\/powershell -Credential $LiveCred -Authentication Basic -AllowRedirection<\/pre>\n<pre lang=\"powershell\">Import-PSSession $Session<\/pre>\n<p><strong>Lock\/Unlock User Account:<\/strong><\/p>\n<pre lang=\"powershell\">Set-MsolUser -UserPrincipalName user@example.com \u2013blockcredential <strong>$false<\/strong><\/pre>\n<pre lang=\"powershell\">Set-MsolUser -UserPrincipalName user@example.com \u2013blockcredential <strong>$true<\/strong><\/pre>\n<p><strong>Configure Mail Forwarding:<\/strong><\/p>\n<pre lang=\"powershell\">Set-Mailbox -Identity user@example.com -ForwardingAddress admin@example.com -DeliverToMailboxAndForward $true<\/pre>\n<p><strong>Configure Send As permissions:<\/strong><\/p>\n<pre lang=\"powershell\">Add-RecipientPermission -Identity user@example.com -Trustee admin@example.com -AccessRights SendAs<\/pre>\n<p>In this command line, &#8220;admin@example.com&#8221; represents the mailbox, contact, or distribution group that you want to grant rights to and is the user who you want to grant Send As rights.<\/p>\n<p><strong>To verify that the permissions are applied:<\/strong><\/p>\n<pre lang=\"powershell\">Get-RecipientPermission -Identity  | Select Trustee, AccessControlType, AccessRights<\/pre>\n<p>In the results, you should be able to confirm thathas Send As rights granted. These rights can be assigned to a user, mailbox or group Active Directory objects.<\/p>\n<p><strong>Grant full mailbox access, Grant a user full mailbox access to a user other than the mailbox owner:<\/strong><\/p>\n<pre lang=\"powershell\">Add-MailboxPermission -Identity user@example.com -User admin@example.com -AccessRights FullAccess -InheritanceType All<\/pre>\n<p>In this command line, &#8220;user@example.com&#8221; represents the mailbox that you want to grant rights to and &#8220;admin@example.com&#8221; is the mailbox of the user who you want to grant Full Access rights.<\/p>\n<p>I always get this messed up! the &#8220;user&#8221; is who&#8217;s account you want to access i.e. helpdesk@ support@ etc. The &#8220;admin&#8221; is the users account who needs the access i.e. dom@ user@ etc.<br \/>\nIf an administrator wants to grant a user access to a <a title=\"Configure Resource Mailbox Options in Windows PowerShell\" href=\"http:\/\/help.outlook.com\/en-gb\/140\/dd569932.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">room mailbox<\/a>, the administrator may want to specify that user as the Owner:<\/p>\n<pre lang=\"powershell\">Add-MailboxPermission -Identity  -Owner<\/pre>\n<p>Only users that have Exchange mailboxes can be granted access to other mailboxes. Users who do not have mailboxes receive a permissions error when they try &nbsp;to access the other mailboxes.<\/p>\n<p><strong>Remove Mailbox Access:<\/strong><\/p>\n<pre lang=\"powershell\">Remove-MailboxPermission user@example.com -User admin@example.com -AccessRights FullAccess -InheritanceType All<\/pre>\n<p><strong>To verify that the permissions are applied to the mailbox:<\/strong><\/p>\n<pre lang=\"powershell\">Get-MailboxPermission -Identity user@example.com | Select User, AccessRights, Deny<\/pre>\n<p>In the results, you should be able to confirm that &lt;Mailbox2&gt; has Full Access rights granted.<\/p>\n<p><strong>Configure &#8220;Send on behalf&#8221; permissions, Grant a user the ability to send mail on behalf of another user:<\/strong><\/p>\n<pre lang=\"powershell\">Set-Mailbox -Identity user@example.com -GrantSendOnBehalfTo admin@example.com<\/pre>\n<p>In this command line, user@example.com represents the mailbox that you want to grant permissions to and admin@example.com is the mailbox of the user who you want to grant access.<\/p>\n<p><strong>To verify that the &#8220;SendOnBehalf&#8221; permissions are applied:<\/strong><\/p>\n<pre lang=\"powershell\">Get-Mailbox&nbsp; -Identity admin@example.com | Select GrantSendOnBehalfTo<\/pre>\n<p><strong>Find out whether a password is set to never expire:<\/strong><\/p>\n<pre lang=\"powershell\">Get-MSOLUser -UserPrincipalName admin@example.com | Select PasswordNeverExpires<\/pre>\n<pre lang=\"powershell\">Get-MSOLUser | Select UserPrincipalName, PasswordNeverExpires<\/pre>\n<p><strong>Set a password to never expire (Individual)<br \/>\n<\/strong><\/p>\n<pre lang=\"powershell\">Set-MsolUser -UserPrincipalName user@example.com -PasswordNeverExpires <strong>$true<\/strong><\/pre>\n<pre lang=\"powershell\">Set-MsolUser -UserPrincipalName user@example.com -PasswordNeverExpires <strong>$false<\/strong><\/pre>\n<p><strong>Set a password expiry (All Users)<\/strong><\/p>\n<pre lang=\"powershell\">Get-MSOLUser | Set-MsolUser -PasswordNeverExpires <strong>$true<\/strong><\/pre>\n<pre lang=\"powershell\">Get-MSOLUser | Set-MsolUser -PasswordNeverExpires <strong>$false<\/strong><\/pre>\n<p><strong>Powershell Commands <\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/help.outlook.com\/en-us\/140\/dd575549.aspx\">http:\/\/help.outlook.com\/en-us\/140\/dd575549.aspx<\/a><\/li>\n<li><a title=\"Mail Forwarding\" href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd351134.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/technet.microsoft.com\/en-us\/library\/dd351134.aspx<\/a> (Mail Forwarding)<\/li>\n<\/ul>\n<p><strong>Useful URLs:<\/strong><\/p>\n<ul>\n<li>Office 365 Portal: <a href=\"https:\/\/portal.microsoftonline.com\/\">https:\/\/portal.microsoftonline.com\/<\/a><\/li>\n<li>Office 365 Mail (direct): <a title=\"Office365 OWA\" href=\"http:\/\/mail.office365.com\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/mail.office365.com<\/a><\/li>\n<\/ul>\n<p><strong>Links:<\/strong><\/p>\n<p><strong>Created Shared mailboxes:<\/strong><br \/>\nNote: This code needs some further work in order to actually create a shared mailbox, but it provides enough of the command line to google a guide.<\/p>\n<pre lang=\"powershell\">Add-MailboxPermission \"support@domain.com\" -User supportMailbox_SG@domain.com -AccessRights FullAccess<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>With the migration of many BPOS accounts to Office 365 there have been some major changes to the back-end resulting in a different method connecting via PowerShell in order to use command line syntax. To use the PowerShell command line syntax for Office 365 you first need to initiate a connection to the 365 servers: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14,40,42],"tags":[],"class_list":["post-916","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-online-services","category-office-365"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pOPt8-eM","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/posts\/916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/comments?post=916"}],"version-history":[{"count":3,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/posts\/916\/revisions"}],"predecessor-version":[{"id":3672,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/posts\/916\/revisions\/3672"}],"wp:attachment":[{"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/media?parent=916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/categories?post=916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/tags?post=916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}