PoshCode Logo PowerShell Code Repository

MoveExch2010SP1Archives by David Pekmez 18 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2035"></script>download | new post

This script allows you to move the archive mailbox for a User or all your users to a database for Exchange 2010 SP1

  1. #=================================================================================
  2. #       MoveArchives.ps1
  3. #
  4. #       THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  5. #       KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  6. #       IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  7. #       PARTICULAR PURPOSE.
  8. #      
  9. #       Description:  
  10. #
  11. #       #       This Script Written By: David Pekmez (http://unifiedit.wordpress.com/)
  12. #
  13. #       Version: 1
  14. #       Last Updated: 29/07/2010
  15. #=================================================================================
  16.  
  17. #=======================================
  18. # Parameter definition
  19. #=======================================
  20. Param(
  21.                 [string] $User,
  22.                 [string] $ArchiveDatabase
  23.                 )
  24.                 If([String]::IsNullOrEmpty($User)) {
  25.                 $User =*
  26. }
  27.  
  28.  
  29. #==========================================================================
  30. # Function that returns true if the incoming argument is a help request
  31. #==========================================================================
  32. function IsHelpRequest
  33. {
  34.         param($argument)
  35.         return ($argument -eq "-?" -or $argument -eq "-help");
  36. }
  37.                
  38. #===================================================================
  39. # Function that displays the help related to this script following
  40. # the same format provided by get-help or <cmdletcall> -?
  41. #===================================================================
  42. function Usage
  43. {
  44.  
  45. @"
  46. NAME: MoveArchives.ps1
  47.  
  48. SYNOPSIS:
  49. Move User's Archive to another Database
  50. Exchange 2010 SP1 Requiered
  51.  
  52. SYNTAX:
  53. MoveArchives.ps1
  54. `t[-User <UserName>]
  55. `t[-ArchiveDatabase <ArchiveDatabaseName>]
  56.  
  57.  
  58. PARAMETERS:
  59. -User (optional)
  60. The Username you want the archive to be moved.
  61. If not used, all users archives will be moved to the target Database.
  62.  
  63. -ArchiveDatabase (required)
  64. The Target Database Name where the archive will be moved
  65.  
  66. -------------------------- EXAMPLE 1 --------------------------
  67.  
  68. .\MoveArchives.ps1 -User dpekmez -ArchiveDatabase ArchiveDB1
  69.  
  70. -------------------------- EXAMPLE 2 --------------------------
  71.  
  72. .\MoveArchives.ps1 -ArchiveDatabase ArchiveDB1
  73.  
  74. "@
  75. }      
  76.  
  77. #=======================================
  78. # Check for Usage Statement Request
  79. #=======================================
  80. $args | foreach { if (IsHelpRequest $_) { Usage; exit; } }
  81.  
  82.  
  83. #==============================================
  84. # Function that validates the script parameters
  85. #==============================================
  86. function ValidateParams
  87. {
  88.         $validInputs = $true
  89.         $errorString =  ""
  90.  
  91.         if ($ArchiveDatabase -eq "")
  92.         {
  93.                 $validInputs = $false
  94.                 $errorString += "`nMissing Parameter: The -ArchiveDatabase parameter is required. Please pass in the desired Target Database Name."
  95.         }
  96.  
  97.         if (!$validInputs)
  98.         {
  99.                 Write-error "$errorString"
  100.         }
  101.  
  102.         return $validInputs
  103. }
  104.  
  105.  
  106. #==============================================
  107. # Move Request
  108. #==============================================
  109.  
  110. Get-Mailbox -identity $User | where { $_.ArchiveDatabase -ne $null } | New-MoveRequest -ArchiveTargetDatabase $ArchiveDatabase –ArchiveOnly

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me