Archive
[EXO] Identifying Validation Errors
$errors = (Get-MsolContact –ObjectID <Object_ID>).Errors
$errors | foreach-object {“nService: " + $_.ErrorDetail.Name.split("/")[0]; "Error Message: "+ $_.ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription}
$errors = (Get-MsolGroup –ObjectID <Object_ID>).Errors
$errors | foreach-object {"nService: ” + $_.ErrorDetail.Name.split(“/”)[0]; “Error Message: “+ $_.ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription}
$errors = (Get-MsolUser -UserPrincipalName “<User_ID>”).Errors
$errors | foreach-object {“`nService: ” + $_.ErrorDetail.Name.split(“/”)[0]; “Error Message: ” + $_.ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription}
Get-MsolUser -HasErrorsOnly -All | ft DisplayName,UserPrincipalName,@{Name=”Error”;Expression={($_.errors[0].ErrorDetail.objecterrors.errorrecord.ErrorDescription)}} -AutoSize -wrap
https://support.microsoft.com/en-au/help/2741233/you-see-validation-errors-for-users-in-the-office-365-portal-or-in-the
1 2 3 4 5 6 7 8 9 |
$output = @() $usererr = Get-MsolUser -HasErrorsOnly Foreach ($user in $usererr) { $output += New-Object psobject -Property @{ user = $user.UserPrincipalName errordetail = $user.Errors.ErrorDetail.Name.split("/")[0] details = $user.Errors.ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription} } $output | export-csv c:\temp\outpute.csv -NoTypeInformation |
1 2 3 4 5 6 7 8 |
function Get-MSOLUserWithValidationError { $usererr = Get-MsolUser -HasErrorsOnly Foreach ($user in $usererr) { Write-output $user.UserPrincipalName; "Service: "+ $user.Errors.ErrorDetail.Name.split("/")[0]; "Error Message: "+ $user.Errors.ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription +"`n" } } |
[EXO][EX2010] Removing dual mailboxes
Ensure you have a user mailbox backup prior to starting the following process as there is potential risk of data loss. Options are to have a third party solution to perform a mailbox backup or export to PST (see new-mailboxexport cmdlet).
- Capture relevant information from on-premise exchange and exchange online.
- Grab the mailbox information (primary and archive) to help determine which mailbox is active and which one to disable (remove)
- get-mailboxstatistics <user>
- get-mailboxstatistics <user> -archive
- get-exomailboxstatistics (exo ps v2)
- Grab the x500 address (legacydn)
- Grab GUID information
- get-recipient <user> | fl *guid*
- Grab the mailbox information (primary and archive) to help determine which mailbox is active and which one to disable (remove)
- Determine which mailbox is active and which one to disable (remove) –
- Removing the on-premise mailbox will require you to delete and recreate the remote mailbox – an object on-premise will need to represent the object on exchange for remote routing.
- Disable the on-premise mailbox – do not remove, or you will remove the AD user object:
- disable-mailbox <user>
- If litigation hold is enabled, you will need to disable the hold, then disable the mailbox.
- Recreate the remote mailbox on-premise
- Enable-RemoteMailbox -Identity <user> -RemoteRoutingAddress “<user>@<tenant>.mail.onmicrosoft.com”
- Associate the GUID and x500 for sync and mail routing:
- Set-RemoteMailbox -exchangeguid <exchange guid> -archiveguid <archive guid> -EmailAddresses X500: <x500>
- Disable the on-premise mailbox – do not remove, or you will remove the AD user object:
- Removing the cloud mailbox
- Remove the user from Office 365 and resync with AD sync.
- remove-msoluser <user>
- remove-msoluser <user> -removefromrecyclebin -force
- Clearing the previous mailbox information
- Set-User <user> -PermanentlyClearPreviousMailboxInfo
- Remove the user from Office 365 and resync with AD sync.
- Removing the on-premise mailbox will require you to delete and recreate the remote mailbox – an object on-premise will need to represent the object on exchange for remote routing.
Accidentally deleted a on-premise mailbox?
- Identify where the disconnected or soft deleted mailbox is.
- $dbs = Get-MailboxDatabase $dbs | foreach {Get-MailboxStatistics -Database $_.DistinguishedName} | where {$_.DisconnectReason -eq “Disabled”} | Format-Table DisplayName,Database,DisconnectDate
- Reconnect the mailbox
- Connect-Mailbox -Identity “<identity>” -Database <database> -User “<user>” -Alias <alias>
Accidentally deleted the on-premise user, but need to restore the data to cloud mailbox?
- Create a new temporary mailbox on-premise to restore the data to.
- Identify where the disconnected or soft deleted mailbox is.
- $dbs = Get-MailboxDatabase $dbs | foreach {Get-MailboxStatistics -Database $_.DistinguishedName} | where {$_.DisconnectReason -eq “Disabled”} | Format-Table DisplayName,Database,DisconnectDate,*guid*
- Restore the primary and archive data to the temporary mailbox
- New-MailboxRestoreRequest -SourceStoreMailbox <mailbox guid> -SourceDatabase <database> -TargetMailbox <mailbox> -AllowLegacyDNMismatch
- New-MailboxRestoreRequest -SourceStoreMailbox<mailbox guid> -SourceDatabase <database> -TargetMailbox <mailbox> -TargetIsArchive
- Export the data to PST (requires rights)
- New–ManagementRoleAssignment –Role “Mailbox Import Export” –User Administrator
- New-MailboxExportRequest -Mailbox <mailbox> -FilePath <path>
- New-MailboxExportRequest -Mailbox <mailbox> -FilePath <path> -isarchive
- Ensure the Exchange Trust Subsystem group has read/write permissions to path
- Check status:
- Get–MailboxExportRequest | where {$_.status –eq “Completed”}
- Remove job:
- Get-MailboxRestoreRequest -Status Completed | Remove-MailboxRestoreRequest
- Get-MailboxRestoreRequest -Status Failed | Remove-MailboxRestoreRequest
- Import to mailbox:
- In Outlook with Exchange Online Mailbox, you can import directly – ensure you do not copy duplicates.
[EX2010][EXO] Forwarding Address Export and Import
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#Load Exchange 2010 Module Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010 -ErrorAction SilentlyContinue #Setup Variables $Filename = "C:\temp\tasks\fowarding_address\export.csv" $header = "UPN,ForwardingSmtpAddress,DeliverToMailboxAndForward" $header | Out-File $Filename #Grab Data $Users = Get-Mailbox -ResultSize Unlimited -Filter { (ForwardingAddress -ne $null) -or (ForwardingSmtpAddress -ne $null) } ForEach ($User in $Users) { if ($user.ForwardingSmtpAddress -ne $null) { $forwardingSmtpAddress = $user.ForwardingSmtpAddress $DeliverToMailboxAndForward = $User.DeliverToMailboxAndForward.ToString() $logstring = "$($user.PrimarySmtpAddress),$($forwardingSmtpAddress),$($DeliverToMailboxAndForward)" $logstring | Out-File $Filename -Append } else { if ($user.ForwardingAddress -ne $null) { $forwardingContact = $user.ForwardingAddress $forwardingContactAddress = (Get-Recipient $forwardingContact).PrimarySmtpAddress $DeliverToMailboxAndForward = $User.DeliverToMailboxAndForward.ToString() $logString = "$($user.PrimarySmtpAddress),$($forwardingContactAddress),$($DeliverToMailboxAndForward)" $logString | Out-File $Filename -Append } } } #Remove Exchange 2010 Module Remove-PSSnapin Microsoft.Exchange.Management.Powershell.E2010 #Connect to Exchange Online $username = "<user name>" $targetdir = (dir $env:LOCALAPPDATA”\Apps\2.0\” -Include CreateExoPSSession.ps1,Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse | Group Directory | ? {$_.Count -eq 2}).Values | sort LastWriteTime -Descending | select -First 1 | select -ExpandProperty FullName import-Module $targetdir\CreateExoPSSession.ps1 $PasswordFile = "Password.txt" $KeyFile = "AES.key" $key = Get-Content $KeyFile $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key) connect-exopssession -credential $MyCredential #Reapply forwarding to migrated EXO mailboxes $Users = Import-Csv $Filename ForEach ($user in $users) { $DeliverToMailboxAndForward = [System.Convert]::ToBoolean($User.DeliverToMailboxAndForward) Set-Mailbox -Identity $($user.UPN) -DeliverToMailboxAndForward $DeliverTomailboxAndForward -ForwardingSmtpAddress $($user.ForwardingSmtpAddress) -whatif } #Kill Session and Remove Module Get-PSSession | Remove-PSSession Get-Module | Remove-Module |
Single mailbox export to PST file
Add member of a role group which has the Mailbox Import Export role
1 |
New-ManagementRoleAssignment -Role "Mailbox Import Export" -User "<user name or alias>" |
Export primary mailbox:
1 |
New-MailboxExportRequest -Mailbox <user> -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst |
Export archive mailbox:
1 |
New-MailboxExportRequest -Mailbox <user> -FilePath \\<server FQDN>\<shared folder name>\<PST name>.pst -isarchive |
More details
[PS][EX2010] E-mails Recieved per day of Month Report
.Synopsis
E-mail Counting Script v1 by ELAU 10/10/19
– Script counts emails received for each day of the current month
.DESCRIPTION
– Script pulls days of the month and counts number of emails received for each day of the current month or days specified into a HTML report.
– Script allows option to e-mail report
.EXAMPLE
– Run count.ps1 without parameters will prompt for required options
.EXAMPLE
– Specify days to go back without sending email report
count.ps1 -mailbox <mailbox to search> -day <days to search back from today>
.EXAMPLE
– Specify days to go back with sending email report
count.ps1 -mailbox <mailbox to search> -day <days to search back from today> -emailto <report to send to>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
<# .Synopsis E-mail Counting Script v1 by EPIC 10/10/19 - Script counts emails received for each day of the current month .DESCRIPTION - Script pulls days of the month and counts number of emails received for each day of the current month or days specified into a HTML report. - Script allows option to e-mail report .EXAMPLE - Run count.ps1 without parameters will prompt for required options .EXAMPLE - Specify days to go back count.ps1 -mailbox <mailbox to search> -day <days to search back from today> .EXAMPLE - Specify days to go back and email report count.ps1 -mailbox <mailbox to search> -day <days to search back from today> -emailto <report to send to> #> # Parameters Param( [Parameter(position=1)] [string]$mailbox, [Parameter(position=2)] [string]$day, [Parameter(position=3)] [string]$emailto ) # Setup Variables $smtpServer = "smtpserver.com" $emailFrom = "from@address.com" $subject = "Recieved e-mails per day" $Path = "c:\temp\test.html" [INT]$year = (Get-date).ToString("yy") [INT]$month = (Get-date).ToString("MM") $monthheader = (Get-date).ToString("MMMM,yyyy") # Prompts for input if no parmeters provided if (!$day) { [INT]$day = (Get-date).ToString("dd") [INT]$days = [datetime]::DaysInMonth($year,$month) } if (!$mailbox) { $mailbox = Read-Host -Prompt "Mailbox to Search (user@firstrepublic.com)" } If ($emailto) { $email = "sure" } elseif (!$emailto) { $email = Read-Host -Prompt "E-mail Report : Yes or No" while("yes","no" -notcontains $email) { $email = Read-Host -Prompt "E-mail Report : Yes or No" } } if ($email -eq "yes") { $emailTo = Read-Host -Prompt "E-mail to send Report (user@firstrepublic.com)" } #HTML HEADER $head = @" <title>E-mail Report</title> <style type="text/css"> table, td { border: 1px solid black; border-collapse:collapse;} tr:nth-child(odd) { background-color:lightgrey; } th { color:black; text-align:left; border: 1px solid black; font:normal 16px verdana, arial, helvetica, sans-serif; font-weight:bold; background-color: #6495ED; padding-left:6px; padding-right:6px; } </style> "@ # HTML TABLE HEADER $body += @" <table> <tr><th colspan="2">$monthheader - $mailbox</th></tr> <tr> <td>Date</td> <td>E-mails Recieved</td> </tr> "@ # Performs the search and adds HTML ROWs $i=1 Do { $start = ((get-date -hour 0 -Minute 0 -Second 0).adddays(-($day-$i+1))) $shortstart = ((get-date).adddays(-($day-$i+1)).ToString("MM-dd-yyyy")) $end = ((get-date -hour 0 -Minute 0 -Second 0).adddays(-($day-($i)))) $emails = Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -Start $start -End $end -EventId "Receive" -Recipient $mailbox $count = ($emails | Measure-Object).count $body += @" <tr> <td>$shortstart</td> <td>$count</td> </tr> "@ $i++ } While ($i -le $day) # HTML FOOTER $body += @" </table> "@ # Add HTML together and ouputs report $HTML = $head + $body $HTML | Out-File $Path # Sends e-mail if email is requested if ($email -eq "yes" -or $email -eq "sure") { Send-MailMessage -From $emailFrom -To $emailTo -Subject $Subject -Body $HTML -BodyAsHtml -SmtpServer $smtpServer -EA Stop 2>> $errorlog } |
[PS] [EX2010] Recoverable Folder Size Report
Recoverable Folder Size Report v1
- Crawls all mailboxes and pulls the recoverableitemsquota size
- Displays top 10 in HTML report
- Full CSV report is generated
- E-mails report with full report
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# Setup E-mail Parameters $smtpServer = "host.server.com" $emailFrom = "from@address.com" $emailTo = @('<to@address.com>') $subject = "Top Recoverable Folder Size - $date" $output = "c:\temp\output.csv" #Import Exchange 2010 Module Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010 -ErrorAction SilentlyContinue #Setup Variables [INT] $RQ = 0 [INT] $RW = 0 [INT] $DIQ = "30" [INT] $DIW = "20" $Path = "c:\temp\test.html" # #Exclusion #Check if all Database Quota matches default $Q = @(Get-mailboxdatabase | foreach {$_.recoverableitemsquota.value.tobytes()/1Gb}) foreach ($IQ in $Q) { If ($IQ -notmatch "$DIQ") { write-host $IQ + "is not set to default settings" $RQ++ } } If ($RQ -ge 1) { echo "default is not set for 1 or more mailboxes"} #Check if all Database Quota matches warning default $W = @(Get-mailboxdatabase | foreach {$_.RecoverableItemsWarningQuota.value.tobytes()/1Gb}) foreach ($IW in $W) { If ($IW -notmatch "$DIW") { write-host $IW + "is not set to default settings" $RW++ } } If ($RW -ge 1) { echo "storage default is not set for 1 or more mailboxes"} $sort = @() $output = "c:\temp\output.csv" $mailboxes = Get-mailbox -resultsize unlimited Foreach ($m in $mailboxes) { $size = Get-MailboxFolderStatistics $m -FolderScope RecoverableItems | ?{$_.Identity -match "Recoverable Items"} $sort = New-Object psobject -Property @{ mailbox = $m.alias mailboxdn = $m.distinguishedname recoversize = [math]::round($size.folderandsubfoldersize.tobytes() /1Gb, 3) } $sort | Export-Csv c:\temp\output.csv -notypeinformation -append $sort ="" } $output = "c:\temp\output.csv" $mailboxesorted = import-csv $output | sort-Object {[INT]$_.recoversize} -Descending | select -First 10 $DiskDetailHTML += "<table>" $DiskDetailHTML += "<tr><th>Mailbox</th><th>Mailbox Database</th><th>Mailbox ARC</th><th>Litigation Hold</th><th>Recoverablesize</th><th width=""400px"">Usage</th></tr>`n" #loop through all mailboxes Foreach ($mbx in $mailboxesorted) { $mbxinfo = get-mailbox $mbx.mailboxdn #grab recoverable folder stats $stat = Get-MailboxFolderStatistics $mbxinfo -FolderScope RecoverableItems | ?{$_.Identity -match "Recoverable Items"} #DB $db = $mbxinfo.database #ARC $arcdb = $mbxinfo.archivedatabase #LIT $lit = $mbxinfo.litigationholdenabled #recoveravle folder size to GB $calcrsize = $stat.folderandsubfoldersize.tobytes()/1GB $rsize = ($calcrsize).ToString("#.#######") $alias = $mbxinfo.alias #percentage $calcpercent = ($rsize/$diq) $percent = ($calcpercent).ToString("P") -replace '\s','' $fpercent = (1-$calcpercent).ToString("P") -replace '\s','' if ($percent -lt 0.01) { # $DiskDetailHTML += "<TR> <TD>$alias</TD> <TD>$db</TD> <TD>$arcdb</TD> <TD>$lit</TD> <TD>$rsize GB</TD> <TD> <table width=""100%""> <tr> <td width=""100%"" bgcolor=""green"" align=""Center"">$fpercent</td> </tr> </table> </td></tr>`n" } else { $DiskDetailHTML += "<TR> <TD>$alias</TD> <TD>$db</TD> <TD>$arcdb</TD> <TD>$lit</TD> <TD>$rsize GB</TD> <TD> <table width=""100%""> <tr> <td width=""$percent"" bgcolor=""Red"" align=""Center"">$percent</td> <td width=""$fpercent"" bgcolor=""green"" align=""Center"">$fpercent</td> </tr> </table> </td></tr>`n" # } } #Define static HTML $HeaderHTML = @" <html> <head> <style type='text/css'> body { background-color:#DCDCDC; } table { border:1px solid gray; font:normal 12px verdana, arial, helvetica, sans-serif; border-collapse: collapse; padding-left:30px; padding-right:30px; } th { color:black; text-align:left; border: 1px solid black; font:normal 16px verdana, arial, helvetica, sans-serif; font-weight:bold; background-color: #6495ED; padding-left:6px; padding-right:6px; } td { border: 1px solid black; padding-left:6px; padding-right:6px; } a.detail { cursor:pointer; color:#1E90FF; text-decoration:underline; } </style> </head> <body> <h1>Recoverable Folder Size Report</h1> <p> "@ #Define Footer HTML $FooterHTML = @" </table> </div> </body> </html> "@ #Combine all the HTML fragments and save to a file $HTML = $HeaderHTML + $DiskDetailHTML + $FooterHTML $HTML | Out-File $Path #> Send-MailMessage -From $emailFrom -To $emailTo -Subject $Subject -Attachment $output -Body $HTML -BodyAsHtml -SmtpServer $smtpServer -EA Stop 2>> $errorlog |
[EX2010][PS] Recover mail items from Exchange
How do I recover an item after its been deleted? So long as the recoverable items purge duration has not exceeded, you can run the below command to pull e-mails.
For more specific searchquery, reference Advanced Query Syntax (AQS).
1 2 3 4 5 6 7 8 |
#type search example Search-mailbox -identity <guid> -SearchQuery 'kind:<type>' -SearchDumpsterOnly -TargetMailbox "<destination mailbox>" -TargetFolder "<destination folder>" -loglevel full $multiple criteria search example: Search-mailbox -identity <guid> -SearchQuery 'kind:<type> AND subject "<subject>"' -SearchDumpsterOnly -TargetMailbox "<destination mailbox>" -TargetFolder "<destination folder>" -loglevel full |
- Meetings
- Tasks
- Notes
- Docs
- Journals
- Contacts
- IM
[PS] Enable TLS 1.2 as default in Powershell
Check Supported protocol
[Net.ServicePointManager]::SecurityProtocol
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Change Net Frame to use TLS 1.2
Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWord
Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWord
[EX2010] Litigation Hold (Legal Hold)
Litigation Hold (Legal Hold)
Used to preserve mailbox and electronically stored information in anticipation of legal proceedings, investigations, and unspecified reasons. Organizations may be required to inform when a user is placed on litigation hold.
Specifications:
- Requires Discovery Management or Legal Hold Mgmt (RBAC) to place a mailbox in legal hold
- Option to enable or disable, no option in 2010 to set start and end dates
- Original copies are maintained when modified
- LitigationHoldDate and LitigationHoldOwner attribute is created when enabled
- Migration to O365: mailboxes on Litigation Hold are preserved after a mailbox is moved
Storage:
When a user deletes a folder other than in the Delete Items folder, the message is ‘moved’. When a user deletes from the Deleted Items folder or does a Shift+Delete (Permanent Deletion), the message disappears from the user’s view, is a ‘soft delete’ and moved to Purge sub-folder of the Recoverable Items folder (Recoverable Items folder is also known as the dumpster in previous versions of Exchange). Recoverable Items folder retains items configured on the mailbox database with a default of 14 days. If Litigation is not enabled, items are purged forever based on reaching the quota limit, or longer than the default or set period.
- Default Quota for Recoverable Items Folder, Warning: 20GB, Items: 30 GB
- MFA continues to process the mailbox
- Deleted items are moved retained in a hidden folder called, Recoverable Items (dumpster) with its own storage, and does not count toward the mailbox quota.
- Recoverable Items folder has 3 sub-folders:
- Deletions: Soft Deleted items are moved here, visible from Recoverable Deleted Items (Visible to users)
- Purges: Deleted items from the Recoverable Items are moved here. Deleted Items exceeding the delete item retention period configured on mailbox database or mailbox are also purged here by MFA. Litigation Hold prevents deletion of items from this folder when enabled. (Not visible to users)
- Versions: Original copies of mailbox items are copied here by process called copy on write, where in specific properties changes on the item will create a copy. (Not Visible to users)
Enable and Disabling Litigation Hold:
1 2 |
Set-Mailbox joe@contoso.com -LitigationHoldEnabled $true Set-Mailbox joe@contoso.com -LitigationHoldEnabled $false |
Checking Sizing for mailboxes in litigation hold:
1 |
Get-Mailbox -ResultSize Unlimited -Filter {LitigationHoldEnabled -eq $true} | Get-MailboxFolderStatistics –FolderScope RecoverableItems | Format-Table Identity,FolderAndSubfolderSize -Auto |
Updating the Size for Recoverable Items when quota is reached:
1 |
Set-Mailbox “Mailbox User” –RecoverableItemsWarningQuota 40GB –RecoverableItemsQuota 50GB |
Processing all Mailboxes in litigation hold:
1 |
Get-Mailbox –Filter {LitigationHoldEnabled –eq $true} | Start-ManagedFolderAssistant |
References:
[PS] Write powershell errors to a text file
Method 1: Try, Catch, Finally
Try: Try to execute a command
Catch: Catches any errors, triggers only for Terminating Errors, so you may need to set a ErrorAction -Stop (EA) for errors that are not terminating.
Finally: Runs regardless if a error occurs.
1 2 3 |
Try { Set-Mailbox -Identity -PrimarySmtpAddress -EA STOP } Catch { $_ | Out-File C:\errors.txt -Append } Finally { Echo "runs no matter what"} |
Method 2: Output error directly to error log
1 |
Set-Mailbox -PrimarySmtpAddress <primarysmtpaddress> 2>> C:\errors.txt |
Method 3: Customize a out-file to a error log
1 2 3 |
"this occurred" | out-file c:\error.log -append $x | out-file c:\error.log -append ${get-date) | out-file c:\error.log -append |