none
Exchange Powershell Scripting for enabling Archive with reporting issue. RRS feed

  • General discussion

  • I have a script that works just fine for enabling Online Archiving and then assign retention policy (Script 1).

    But when I add a line to export a report to a text, it only does it for the last person in the text file list.

    If I was to run a script separately (Script 2) and assign the text file of the list of users it works great (see example of this script bellow), but when I try to integrate this script to the script that uses arguments to identify which users to enable Online Archiving, assign Retention Policy and then create a report text file it only spits out the results for the last user in the list.

    Script 1

    If ($Args.Count -eq 0) {
    write-host “You need to specify a file with a list of users as a parameter at the command line!!!”
    Exit
    }
    $users = get-content $args[0]
    foreach ($u in $users) {
    $MailboxDatabase= (Get-Mailbox $U).Database
    $ArchiveDatabase= “Archive01”
    $RetentionPolicy= “Retention Policy”
    Enable-Mailbox $U -Archive -ArchiveDatabase $ArchiveDatabase
    set-mailbox $U -retentionpolicy $RetentionPolicy
    write-host “Done processing $u…”

    Script 2

    Get-Content "C:\scripts\Exchange\Online Archive Enable Script\Group4_List1_Arch_Enable.txt" | Get-Mailbox | FT Name,WindowsEmailAddress,Archivedatabase >"C:\scripts\Exchange\Online Archive Enable Script\Group4_List1_Arch_Enable_Report.txt"

    Script 3 This is what I want to work

    If ($Args.Count -eq 0) {
    write-host “You need to specify a file with a list of users as a parameter at the command line!!!”
    Exit
    }
    $users = get-content $args[0]
    foreach ($u in $users) {
    $MailboxDatabase= (Get-Mailbox $U).Database
    $ArchiveDatabase= “Archive01”
    $RetentionPolicy= “Retention Policy”
    Enable-Mailbox $U -Archive -ArchiveDatabase $ArchiveDatabase
    set-mailbox $U -retentionpolicy $RetentionPolicy
    write-host “Done processing $u…”

    (Get-Mailbox $u) | FT Name,WindowsEmailAddress,Archivedatabase >"c:\data\TEST.txt"
    }

    Please have a look and help.

    Thanks a bunch in advance.


    Friday, September 25, 2015 5:06 PM

All replies

  • Note that you script is incomplete and has smart quotes which can cause issues:

    If ($Args.Count -eq 0) {
         write-host “You need to specify a file with a list of users as a parameter at the command line!!!”
         Exit
    }
    $users = get-content $args[0]
    foreach ($u in $users) {
         $MailboxDatabase= (Get-Mailbox $U).Database
         $ArchiveDatabase='Archive01'
         $RetentionPolicy='Retention Policy'
         Enable-Mailbox $U -Archive -ArchiveDatabase $ArchiveDatabase
         set-mailbox $U -retentionpolicy $RetentionPolicy
         write-host "Done processing $u…"

    Use single quotes when expansion not required and do not use smart quotes.


    \_(ツ)_/

    Friday, September 25, 2015 5:20 PM
  • You are just throwing a bunch of pieces on the screen and saying "make this work".  This forum is not a repair site for scripts you have found oon the Internet (smart quotes tell us that). 

    Please post a script that you are using and ask a specific question.


    \_(ツ)_/

    Friday, September 25, 2015 5:23 PM
  • This is the script that someone had suggested I use for this task.  I am not a scripter, nor do I claim to be.  I am just trying to make my work easier by using a script to handle multiple tasks simultaneously. 

    I have used this script successfully with the exception of the report being created at the end.  I am looking for a solution for giving a report of the successful mailboxes getting Archive turned on with retention policy.

    If ($Args.Count -eq 0) {
    write-host “You need to specify a file with a list of users as a parameter at the command line!!!”
    Exit
    }
    $users = get-content $args[0]
    foreach ($u in $users) {
    $MailboxDatabase= (Get-Mailbox $U).Database
    $ArchiveDatabase= “Archive01”
    $RetentionPolicy= “Retention Policy”
    Enable-Mailbox $U -Archive -ArchiveDatabase $ArchiveDatabase
    set-mailbox $U -retentionpolicy $RetentionPolicy
    write-host “Done processing $u…”
    (Get-Mailbox $U) | ft name, archivedatabase >c:\data\Archive01report.txt
    }

    Friday, September 25, 2015 7:30 PM
  • And what is the error you are getting.  THe mailboxes changed are listed in the file you are outputting to.  Change > to >> to see all outputs.


    \_(ツ)_/

    Friday, September 25, 2015 7:39 PM