{"id":2512,"date":"2018-06-14T23:35:22","date_gmt":"2018-06-14T23:35:22","guid":{"rendered":"http:\/\/microsoftgeek.com\/?p=2512"},"modified":"2018-06-14T23:36:01","modified_gmt":"2018-06-14T23:36:01","slug":"powershell-how-to-recover-deleted-emails-and-items-using-windows-powershell","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=2512","title":{"rendered":"PowerShell &#8211; How to recover deleted emails and items using Windows PowerShell"},"content":{"rendered":"<p>Occasionally accidents happen and important emails or things like calendar events get deleted. If you are unlucky you won&#8217;t be able to recover the deleted items the easy way over Microsoft Exchange server and will have to use PowerShell. Below are the steps to take to do this:<\/p>\n<ol>\n<li data-aria-posinset=\"1\" data-aria-level=\"2\"><b>Make Sure you are a member of the Discover Management Role Group<\/b>\u00a0Before you can recover the deleted item, you need to be a member of the Discover Management Role Group (DMRG). This will allow you to search for messages across multiple mailboxes in your organization. If you are not a member of the DMRG then follow this link that will show you steps to assign yourself that role:<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li data-aria-posinset=\"1\" data-aria-level=\"2\"><b>Startup PowerShell and put in your credentials, where you&#8217;re getting the sessions from and importing<\/b>\u00a0The next thing to do is start up PowerShell. Type in the code below:<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">$cred = Get-Credential\u00a0This get the credentials for the exchange\u00a0server.$session\u00a0= New-PSSession\u00a0-ConfigurationName\u00a0Microsoft.Exchange\u00a0-ConnectionUri\u00a0https:\/\/ps.outlook.com\/powershell\/\u00a0-Credential $cred -Authentication Basic \u2013AllowRedirection\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>This sets up a connections with the exchange server\u00a0Import-PSSession\u00a0$session\u00a0This will import the sessions.<\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li data-aria-posinset=\"3\" data-aria-level=\"2\"><b>Search for and recover the email<\/b>\u00a0Now that PowerShell is setup we can move onto recovering the deleted item.\u00a0<b>Note: items in square brackets [example] are to be replaced by your\u00a0requirements.<\/b>To\u00a0retrieve a single item follow these steps: First you need to search for the email:<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">search-Mailbox [user] -SearchDumpsterOnly\u00a0-SearchQuery\u00a0[search query] -TargetMailbox\u00a0&#8220;Discovery Search Mailbox&#8221; -TargetFolder\u00a0[search name] -LogLevel\u00a0Full\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>Once you&#8217;ve found the item you can recover it:<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">Search-Mailbox &#8220;Discovery Search Mailbox&#8221; -SearchQuery\u00a0[search query] -TargetMailbox\u00a0[user] -TargetFolder\u00a0inbox\u00a0\u00a0<\/span><\/p>\n<p><span style=\"color: #ff0000;\">\u00a0<\/span><\/p>\n<p>If you wish to recover all\u00a0permantely\u00a0deleted items from the purged items folder run this line of code:<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">Search-Mailbox\u00a0user@domain.com\u00a0-SearchDumpsterOnly\u00a0-TargetMailbox\u00a0&#8220;Discovery Search Mailbox&#8221; -TargetFolder\u00a0RecoveredItems\u00a0-LogLevel\u00a0Full\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Occasionally accidents happen and important emails or things like calendar events get deleted. If you are unlucky you won&#8217;t be able to recover the deleted items the easy way over Microsoft Exchange server and will have to use PowerShell. Below are the steps to take to do this: Make Sure you are a member of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[],"class_list":["post-2512","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2512"}],"version-history":[{"count":2,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2512\/revisions"}],"predecessor-version":[{"id":2514,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2512\/revisions\/2514"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}