{"id":195,"date":"2009-05-11T12:01:54","date_gmt":"2009-05-11T11:01:54","guid":{"rendered":"http:\/\/www.edwardsd.co.uk\/work\/?p=195"},"modified":"2019-07-25T20:14:16","modified_gmt":"2019-07-25T19:14:16","slug":"exchange-mailbox-permissions-using-powershell-command-line","status":"publish","type":"post","link":"https:\/\/www.edwardsd.co.uk\/work\/2009\/05\/exchange-mailbox-permissions-using-powershell-command-line\/","title":{"rendered":"Exchange 2007 | EMC Powershell"},"content":{"rendered":"<p><strong>Open &#8220;Exchange Management Shell&#8221; <\/strong><\/p>\n<p><strong>Shortcut refs to: <\/strong>(C:\\WINDOWS\\system32\\windowspowershell\\v1.0\\powershell.exe -PSConsoleFile &#8220;C:\\Program Files\\Microsoft\\Exchange Server\\bin\\exshell.psc1&#8221; -noexit -command &#8220;. &#8216;C:\\Program Files\\Microsoft\\Exchange Server\\bin\\Exchange.ps1&#8242;&#8221;)<\/p>\n<p>If this is not installed, look at the following article for installing Exchange: <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/bb123694(EXCHG.80).aspx\">http:\/\/technet.microsoft.com\/en-us\/library\/bb123694(EXCHG.80).aspx<\/a><\/p>\n<p><strong><span style=\"text-decoration: underline;\">Don&#8217;t get the Exchange Management Shell &amp; Windows Powershell mixed up &#8211; for Windows Powershell see:<\/span><\/strong><\/p>\n<hr \/>\n<p><strong>Adding send as permissions to mailbox:<\/strong><\/p>\n<pre lang=\"basic\">Add-ADPermission \"Mailbox\" -User \"Domain\\User\" -Extendedrights \"Send As\"<\/pre>\n<p><strong>Adding full access permissions to mailbox:<\/strong><\/p>\n<pre lang=\"basic\">Add-MailboxPermission \"Mailbox\" -User \"Trusted User\" -AccessRights FullAccess<\/pre>\n<p><strong>Adding full access permissions to <span style=\"text-decoration: underline;\">ALL<\/span> mailboxes:<\/strong><\/p>\n<pre lang=\"basic\">Get-Mailboxdatabase | Add-AdPermission -User \"Username\" -AccessRights GenericAll<\/pre>\n<p><strong>List all mailbox stores in size order:<\/strong><\/p>\n<pre lang=\"basic\">Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label=\"TotalItemSize(MB)\";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount<\/pre>\n<p><strong>List all mailbox stores in size order (Export to CSV \/ on Desktop):<\/strong><\/p>\n<pre lang=\"basic\">Get-MailboxStatistics -Database \u201cMailbox Database\u201d | Select DisplayName, LastLoggedOnUserAccount, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime | Export-CSV test.csv<\/pre>\n<p><strong>List all mailbox stores in size order:<\/strong><\/p>\n<pre lang=\"basic\">Get-MailboxStatistics -Database \u201cMailbox Database\u201d | Sort -Property TotalItemsize | Format-Table DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToMB()};label=\u201dSize(MB)\u201d}, LastLogonTime, LastLogoffTime<\/pre>\n<hr \/>\n<p><strong>Purge all disconnected mailboxes:<\/strong><\/p>\n<p>(Add all the disconnected mailboxes into a var by typing the below:)<\/p>\n<pre lang=\"basic\">$users = Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid,Database<\/pre>\n<p><strong>Purge all the disconnected mailboxes in the previously made var by typing the below:<\/strong><\/p>\n<pre lang=\"basic\">$users | ForEach { Remove-Mailbox -Database $_.Database -StoreMailboxIdentity $_.MailboxGuid -confirm:$false }<\/pre>\n<hr \/>\n<p><strong>List all Public folder email addresses (output to file)\u00a0<\/strong><\/p>\n<p>I had a request for all the email addresses associated to public mailboxes, as these are not displayed on the client in Outlook.<\/p>\n<p><strong>Method1:<\/strong><\/p>\n<p>Displays a list of Public Folders &amp; Email addresses output to TXT File (FL = Formats list with full text)<\/p>\n<pre lang=\"basic\">Get-PublicFolder -Recurse | Get-MailPublicFolder | fl DisplayName,Emailaddresses &gt; c:\\publicfolders_list.txt<\/pre>\nngg_shortcode_0_placeholder\n<p><strong>Method2:<\/strong> Displays a list of Public Folders &amp; Email addresses output to CSV File:<\/p>\n<pre lang=\"basic\"># Export-CSV PowerShell Spreadsheet\r\nClear-Host\r\n$FilePath = \"c:\\publicfolders.csv\"\r\nGet-MailPublicFolder | Select-Object DisplayName -expand emailaddresses| Export-CSV $FilePath<\/pre>\nngg_shortcode_1_placeholder\n<hr \/>\n<p><strong>List Exchange 2007 Product Version<\/strong><\/p>\n<pre lang=\"basic\">Get-ExchangeServer | fl name,edition,admindisplayversion<\/pre>\n<hr \/>\n<p><strong>List Exchange 2007 Database Size<\/strong><\/p>\n<pre lang=\"basic\">Get-MailboxDatabase | foreach-object {add-member -inputobject $_ -membertype noteproperty -name mailboxdbsizeinGB -value ([math]::Round(([int64](get-wmiobject cim_datafile -computername $_.server -filter ('name=''' + $_.edbfilepath.pathname.replace(\"\\\",\"\\\\\") + '''')).filesize \/ 1GB),2)) -passthru} | Sort-Object mailboxdbsizeinGB -Descending | format-table identity,mailboxdbsizeinGB<\/pre>\n<hr \/>\n<p><strong>List Exchange 2007 GUID<\/strong><\/p>\n<pre lang=\"basic\">Get-MailboxDatabase -Identity \"&lt;server name&gt;\\&lt;storage group name&gt;\\&lt;database name&gt;\" | Format-Table Name, GUID<\/pre>\n<hr \/>\n<p><strong>Public Folder Permissions via Powershell<\/strong><\/p>\n<p>Type the below, replacing &#8216;public folder name&#8217; with your public folder name\/path and you must keep the \\ at the front of it and also replace &#8216;username&#8217; with the username:<\/p>\n<pre lang=\"basic\">Add-PublicFolderClientPermission -Identity \"\\public folder name\" -AccessRights Owner -User username<\/pre>\n<p><strong>Owner can be replaced with the following roles:<\/strong><\/p>\n<ul>\n<li>None<\/li>\n<li>Owner<\/li>\n<li>PublishingEditor<\/li>\n<li>Editor<\/li>\n<li>PublishingAuthor<\/li>\n<li>Author<\/li>\n<li>Non-Editing Author<\/li>\n<li>Reviewer<\/li>\n<li>Contributor<\/li>\n<\/ul>\n<p><strong>Source: <\/strong><a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/bb310789%28EXCHG.80%29.aspx\">http:\/\/technet.microsoft.com\/en-us\/library\/bb310789(EXCHG.80).aspx<\/a><\/p>\n<hr \/>\n<p><strong>Finding a Mailbox via Powershell<\/strong><\/p>\n<pre lang=\"basic\">Get-Mailbox -identity findmyemail@mydomain.com<\/pre>\n<hr \/>\n<p><strong>List Members of a Distribution List<\/strong><strong> (output on screen)<\/strong><\/p>\n<pre lang=\"basic\">Get-DistributionGroupMember-identity \"staff.technical\"<\/pre>\n<p><strong>List Members of a Distribution List<\/strong><strong> including their primary email address and formatted (output to CSV on C:\\)<\/strong><\/p>\n<pre lang=\"basic\">Get-DistributionGroupMember \u2013identity \u201cstaff.technical\u201d | ft name, primarysmtpaddress &gt; c:\\members.csv<\/pre>\n<hr \/>\n<p><strong>List Members of a Dynamic Distribution List<\/strong><\/p>\n<pre lang=\"basic\">$group = Get-DynamicDistributionGroup \u2013identity \u201cAllStaff-DL\u201d\r\nGet-Recipient \u2013RecipientPreviewFilter $group.RecipientFilter | sort name | select name &gt; C:\\dlist_members.txt<\/pre>\n<p><!--more--><\/p>\n<p><strong>Reference:<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/geektank.net\/2010\/05\/exchange-2007-finding-out-what-version-and-service-pack-youre-running\/\">http:\/\/geektank.net\/2010\/05\/exchange-2007-finding-out-what-version-and-service-pack-youre-running\/<\/a><\/li>\n<li><a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/bb232092%28EXCHG.80%29.aspx\">http:\/\/technet.microsoft.com\/en-us\/library\/bb232092(EXCHG.80).aspx<\/a><\/li>\n<li><a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/aa998066%28EXCHG.65%29.aspx\">http:\/\/technet.microsoft.com\/en-us\/library\/aa998066(EXCHG.65).aspx<\/a><\/li>\n<li><a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en-US\/exchangesvradmin\/thread\/0c7ae473-25f1-48e6-acf9-b781aad6774b\">http:\/\/social.technet.microsoft.com\/Forums\/en-US\/exchangesvradmin\/thread\/0c7ae473-25f1-48e6-acf9-b781aad6774b<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Open &#8220;Exchange Management Shell&#8221; Shortcut refs to: (C:\\WINDOWS\\system32\\windowspowershell\\v1.0\\powershell.exe -PSConsoleFile &#8220;C:\\Program Files\\Microsoft\\Exchange Server\\bin\\exshell.psc1&#8221; -noexit -command &#8220;. &#8216;C:\\Program Files\\Microsoft\\Exchange Server\\bin\\Exchange.ps1&#8242;&#8221;) If this is not installed, look at the following article for installing Exchange: http:\/\/technet.microsoft.com\/en-us\/library\/bb123694(EXCHG.80).aspx Don&#8217;t get the Exchange Management Shell &amp; Windows Powershell mixed up &#8211; for Windows Powershell see: Adding send as permissions to mailbox: Add-ADPermission [&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":[25,30],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-exchange-2007","category-powershell"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pOPt8-39","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/posts\/195","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=195"}],"version-history":[{"count":5,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":3546,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/posts\/195\/revisions\/3546"}],"wp:attachment":[{"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edwardsd.co.uk\/work\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}