<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>A Collection of Random Thoughts : Powershell</title><link>http://blogs.technet.com/benw/archive/tags/Powershell/default.aspx</link><description>Tags: Powershell</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Move Mailbox from a CSV Import file</title><link>http://blogs.technet.com/benw/archive/2008/06/02/move-mailbox-from-a-csv-import-file.aspx</link><pubDate>Mon, 02 Jun 2008 16:53:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3064881</guid><dc:creator>benw</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.technet.com/benw/comments/3064881.aspx</comments><wfw:commentRss>http://blogs.technet.com/benw/commentrss.aspx?PostID=3064881</wfw:commentRss><wfw:comment>http://blogs.technet.com/benw/rsscomments.aspx?PostID=3064881</wfw:comment><description>&lt;P&gt;A while back, I had promised to write another post detailing how to use Import-CSV and then run Move-Mailbox against the users in that CSV file.&amp;nbsp; Well, quite a bit of time has passed since then, and getting this figured out proved a little more difficult than I thought it would be.&amp;nbsp; I finally got it worked out, though.&lt;/P&gt;
&lt;P&gt;Here are the details of the setup.&amp;nbsp; You have users that you want to split up between several target databases.&amp;nbsp; In my CSV file, I have 3 columns, as outlined below (sample file)&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Name, Username, TargetDB&lt;/P&gt;
&lt;P&gt;A user, auser, "Server\Storage Group\Mailbox Database" &lt;BR&gt;B user, buser, "Server\Storage Group\Second Database" &lt;BR&gt;C user, cuser, "Server\Storage Group\Third Database"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The TargetDB column means that you will have to do a little bit of legwork in determining where you want to put the users, and populate that column, but it shouldn't take too much effort.&lt;/P&gt;
&lt;P&gt;Next, we'll start writing the script itself.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;################################################################## &lt;BR&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # &lt;BR&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Script to move mailboxes multithreaded from CSV import&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # &lt;BR&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # &lt;BR&gt;################################################################## &lt;/P&gt;
&lt;P&gt;write-output "Moving mailboxes from CSV import" &lt;/P&gt;
&lt;P&gt;#First we are going to import from your csv file &lt;BR&gt;#where the CSV file contains 3 columns.&amp;nbsp; Name, Username and TargetDB &lt;/P&gt;
&lt;P&gt;$users = import-csv c:\userimport.csv &lt;/P&gt;
&lt;P&gt;#Now we are going to filter the list down and get a &lt;BR&gt;#list of just the users on the first database &lt;/P&gt;
&lt;P&gt;$db1 = $users| where {$_.targetdb -like "*mailbox database"} | &lt;BR&gt;foreach { $_.name } | get-mailbox &lt;/P&gt;
&lt;P&gt;#getting a list of the users on the second target database &lt;/P&gt;
&lt;P&gt;$db2 = $users | where {$_.targetdb -like "*Second Database"} | &lt;BR&gt;foreach { $_.name } | get-mailbox &lt;/P&gt;
&lt;P&gt;#Repeat the above line for each additional database that you have.&lt;/P&gt;
&lt;P&gt;#Now we move each group of users to their respective databases &lt;/P&gt;
&lt;P&gt;$db1 | move-mailbox -targetdatabase "E2K7-2\First Storage Group\Mailbox Database" -confirm:$false -maxthreads:10 &lt;/P&gt;
&lt;P&gt;$db2 | move-mailbox -targetdatabase "E2K7-2\Second Storage Group\Second Database" -confirm:$false -maxthreads:10 &lt;/P&gt;
&lt;P&gt;#Repeat the above line for each additional mailbox database that you have&lt;/P&gt;
&lt;P&gt;write-output "Completed Mailbox moves from CSV file"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I first tried to get this working with just one command, but kept failing on the target database portion.&amp;nbsp; When I was creating my arrays, I had a separate array for the target database, but the problem I kept running into was that the value for the array was only being recognized as the last value in the CSV file.&amp;nbsp; So if Third Database was the last value for TargetDB, that was where all users ended up being moved.&amp;nbsp; After multiple failed attempts to correct that, I decided that the best way to approach this would be to filter the CSV and move all users with a common target database, then move on to the next group.&amp;nbsp; It still achieves the desired result of being able to take advantage of multi-threading, and it also does everything in one shot.&lt;/P&gt;
&lt;P&gt;If you have any suggestions for improvement, please feel free to pass on your suggestions.&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3064881" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/benw/archive/tags/exchange+2007/default.aspx">exchange 2007</category><category domain="http://blogs.technet.com/benw/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://blogs.technet.com/benw/archive/tags/Exchange/default.aspx">Exchange</category></item><item><title>Exchange 2007 Advanced Move Mailbox Powershell commands</title><link>http://blogs.technet.com/benw/archive/2007/08/28/exchange-2007-advanced-move-mailbox-powershell-commands.aspx</link><pubDate>Wed, 29 Aug 2007 01:54:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:1849466</guid><dc:creator>benw</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.technet.com/benw/comments/1849466.aspx</comments><wfw:commentRss>http://blogs.technet.com/benw/commentrss.aspx?PostID=1849466</wfw:commentRss><wfw:comment>http://blogs.technet.com/benw/rsscomments.aspx?PostID=1849466</wfw:comment><description>&lt;P&gt;By now, you should be familiar with the day to day Powershell commands, so here is one that uses the foreach command.&amp;nbsp; Foreach is used to loop through a given set of items (an array), and perform an action on each one.&lt;/P&gt;
&lt;P&gt;As an example, let's say that you want to perform a Cross-Org mailbox move, but you want to use Get-Mailbox first to get a list of mailboxes.&amp;nbsp; Just using the standard filtering, you have limited options.&amp;nbsp; You can filter 1. By a specific Organizational Unit; 2. By a specific Exchange server; 3. Don't filter at all - return all users; 4. Specify an identity to only return a single mailbox.&amp;nbsp; Now, that's nice that these filters exist, and they are pretty easy to use.&amp;nbsp; You can reference the help for Get-Mailbox for more details (get-help get-mailbox -full).&amp;nbsp; However, what if you only want to move a handful of mailboxes?&amp;nbsp; You need to do some more work.&lt;/P&gt;
&lt;P&gt;First, you'll need to define an array by specifying a variable.&amp;nbsp; You also need to know the alias of the users that you are wanting to move.&lt;/P&gt;
&lt;P&gt;$mboxes = "user1","user2","user3","user4"&lt;/P&gt;
&lt;P&gt;You have now successfully created an array.&amp;nbsp; Now, you can perform an action on that array using the Foreach command.&amp;nbsp; The basic usage of the foreach command is as follows.&lt;/P&gt;
&lt;P&gt;foreach ($&amp;lt;item&amp;gt; in $&amp;lt;collection&amp;gt;) {&amp;lt;command_block&amp;gt;}&lt;/P&gt;
&lt;P&gt;One thing to remember is that $&amp;lt;item&amp;gt; also references a variable, but it is dynamically created, and you can call it whatever you want.&amp;nbsp; In our case,&amp;nbsp;the resulting command&amp;nbsp;would look something like this.&amp;nbsp; I've chosen to use $mb for the$&amp;lt;item&amp;gt; variable.&amp;nbsp; We'll start out by simply getting the mailbox information for those users to make sure it works, then we'll move on to the more complex move portion.&lt;/P&gt;
&lt;P&gt;Note that unless your current account has rights in both forests, you will still need to pass the -credential string, and you will need to define a variable for the credentials using get-credential.&amp;nbsp; To make things easier, I always use $s for the Source Forest credentials, and $t for the Target Forest credentials.&lt;/P&gt;
&lt;P&gt;foreach ($mb in $mboxes) {get-mailbox $mb -DomainController &amp;lt;source DC FQDN&amp;gt; -Credential $s}&lt;/P&gt;
&lt;P&gt;You should now have a list on your screen that looks something like this.&lt;/P&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=2 width=686 border=0 unselectable="on"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=158&gt;&lt;U&gt;Name&lt;/U&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=134&gt;&lt;U&gt;Alias&lt;/U&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=187&gt;&lt;U&gt;ServerName&lt;/U&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=204&gt;&lt;U&gt;ProhibitSendQuota&lt;/U&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=158&gt;User 1&lt;/TD&gt;
&lt;TD class="" vAlign=top width=134&gt;user1&lt;/TD&gt;
&lt;TD class="" vAlign=top width=187&gt;2k3servername&lt;/TD&gt;
&lt;TD class="" vAlign=top width=205&gt;unlimited&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=158&gt;User 2&lt;/TD&gt;
&lt;TD class="" vAlign=top width=134&gt;user2&lt;/TD&gt;
&lt;TD class="" vAlign=top width=187&gt;2k3servername&lt;/TD&gt;
&lt;TD class="" vAlign=top width=205&gt;unlimited&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=158&gt;User 3&lt;/TD&gt;
&lt;TD class="" vAlign=top width=134&gt;user3&lt;/TD&gt;
&lt;TD class="" vAlign=top width=187&gt;2k3servername&lt;/TD&gt;
&lt;TD class="" vAlign=top width=205&gt;unlimited&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=158&gt;User 4&lt;/TD&gt;
&lt;TD class="" vAlign=top width=134&gt;user4&lt;/TD&gt;
&lt;TD class="" vAlign=top width=187&gt;2k3servername&lt;/TD&gt;
&lt;TD class="" vAlign=top width=205&gt;unlimited&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;Now that we are sure that the results are being returned properly, let's include the move-mailbox command.&amp;nbsp; First, I'll show you what &lt;U&gt;doesn't&lt;/U&gt; work.&lt;/P&gt;
&lt;P&gt;foreach ($mb in $mboxes) {get-mailbox $mb -DomainController &amp;lt;source DC FQDN&amp;gt; -Credential $s} | move-mailbox -TargetDatabase "Server\Storage Group\Database" -GlobalCatalog &amp;lt;target GC FQDN&amp;gt; -SourceForestCredential $s -SourceForestGlobalCatalog &amp;lt;source GC FQDN&amp;gt; -TargetForestCredential $t -AllowMerge -SourceMailboxCleanupOptions deletesourcemailbox&lt;/P&gt;
&lt;P&gt;You might think this would work, because previous experience with Powershell has taught you about Pipelining, but it will return an error indicating you have an&amp;nbsp;empty pipe element, which is not permitted.&amp;nbsp; In order to get this to work, you actually have to include the Pipeline within the command block.&amp;nbsp; I'm going to move the end brace } to the end of the statement.&lt;/P&gt;
&lt;P&gt;foreach ($mb in $mboxes) {get-mailbox $mb -DomainController &amp;lt;source DC FQDN&amp;gt; -Credential $s | move-mailbox -TargetDatabase "Server\Storage Group\Database" -GlobalCatalog &amp;lt;target GC FQDN&amp;gt; -SourceForestCredential $s -SourceForestGlobalCatalog &amp;lt;source GC FQDN&amp;gt; -TargetForestCredential $t -AllowMerge -SourceMailboxCleanupOptions deletesourcemailbox}&lt;/P&gt;
&lt;P&gt;The above command will loop through each user in your array, and perform the move-mailbox command.&amp;nbsp; You should note that the command I used assumes that the user account has already been migrated to the target domain by using a migration tool such as the Active Directory Migration Tool, and that you have migrated SID History (The SID is used to match the source mailbox to a target account).&amp;nbsp; The other option would be to include the -NTAccountOU parameter, and have Exchange 2007 create a disabled user account, but this is much less desirable, as it ends up creating a linked mailbox instead of a normal user account.&lt;/P&gt;
&lt;P&gt;[update]&lt;BR&gt;Thanks to comments from some of you, who pointed out that using foreach, while it *does* work as it is shown above, it isn't optimal because it passes the results serially.&amp;nbsp; In other words, it means that it will pass the first result to move-mailbox, then it will wait to pass the next result until the first loop completes.&amp;nbsp; This will result in move-mailbox being called 4 times (for the example above), more if you have a larger list.&amp;nbsp; It also doesn't take advantage of the multi-threading capability of move-mailbox.&lt;/P&gt;
&lt;P&gt;In order to make it work properly, you can either simply specify the array, or you can pass the array into the foreach loop (instead of specifying each item in the array).&amp;nbsp; Examples below.&lt;/P&gt;
&lt;P&gt;$mboxes | get-mailbox $mb -DomainController &amp;lt;source DC FQDN&amp;gt; -Credential $s | move-mailbox -TargetDatabase "Server\Storage Group\Database" -GlobalCatalog &amp;lt;target GC FQDN&amp;gt; -SourceForestCredential $s -SourceForestGlobalCatalog &amp;lt;source GC FQDN&amp;gt; -TargetForestCredential $t -AllowMerge -SourceMailboxCleanupOptions deletesourcemailbox&lt;/P&gt;
&lt;P&gt;foreach&amp;nbsp;{ $mboxes }&amp;nbsp;| get-mailbox $mb -DomainController &amp;lt;source DC FQDN&amp;gt; -Credential $s | move-mailbox -TargetDatabase "Server\Storage Group\Database" -GlobalCatalog &amp;lt;target GC FQDN&amp;gt; -SourceForestCredential $s -SourceForestGlobalCatalog &amp;lt;source GC FQDN&amp;gt; -TargetForestCredential $t -AllowMerge -SourceMailboxCleanupOptions deletesourcemailbox&lt;/P&gt;
&lt;P&gt;What I'm learning here is that there is a LOT to learn about Powershell!!!&lt;/P&gt;
&lt;P&gt;Thanks to Devin Ganger for pointing out the limitation, and thanks to Evan Dodds for helping with the correct usage.&amp;nbsp; I'll be posting a followup to this with some more information on moving mailboxes using a csv file, and using other filters to get the list you want.&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=1849466" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/benw/archive/tags/exchange+2007/default.aspx">exchange 2007</category><category domain="http://blogs.technet.com/benw/archive/tags/Powershell/default.aspx">Powershell</category></item><item><title>Add-ExchangeAdministrator and setting the scope to multiple servers with powershell</title><link>http://blogs.technet.com/benw/archive/2007/05/23/add-exchangeadministrator-and-setting-the-scope-to-multiple-servers-with-powershell.aspx</link><pubDate>Wed, 23 May 2007 20:13:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:1031036</guid><dc:creator>benw</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/benw/comments/1031036.aspx</comments><wfw:commentRss>http://blogs.technet.com/benw/commentrss.aspx?PostID=1031036</wfw:commentRss><wfw:comment>http://blogs.technet.com/benw/rsscomments.aspx?PostID=1031036</wfw:comment><description>&lt;P&gt;So you want to add a new Exchange administrator and set the scope to multiple servers, but the management shell won't allow you to do this?&lt;/P&gt;
&lt;P&gt;Here is what happens.&lt;/P&gt;
&lt;P&gt;Add-ExchangeAdministrator -identity &amp;lt;user&amp;gt; -role ServerAdmin -scope "server1","server2"&lt;/P&gt;
&lt;P&gt;Error: Add-ExchangeAdministrator : cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Scope'. Specified method is not supported.&lt;/P&gt;
&lt;P&gt;Here's the solution.&lt;/P&gt;
&lt;P&gt;First, you need to build an array that contains the servers in question.&lt;/P&gt;
&lt;P&gt;[PS] C:\&amp;gt;$ExServers = "Server1","Server2","Server3"&lt;/P&gt;
&lt;P&gt;[PS] C:\&amp;gt; foreach ($server in $exservers) { Add-ExchangeAdministrator -identity &amp;lt;user&amp;gt; -role ServerAdmin -scope $server }&lt;/P&gt;
&lt;P&gt;Now the result is a success, and you will see the appropriate message indicating that the user has been added, and that to fully administer the Exchange server, you should add the user to the local admins group on the server.&lt;/P&gt;
&lt;P&gt;Running Get-ExchangeAdministrator will also now show this user in the list with a separate entry for each server.&lt;/P&gt;
&lt;P&gt;Now, one more note here.&amp;nbsp; Remember that arrays are only maintained for your specific powershell session.&amp;nbsp; As soon as you close Powershell, you will lose any defined arrays (or variables) unless you have taken actions (for example, modified your powershell profile) to include them.&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=1031036" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/benw/archive/tags/exchange+2007/default.aspx">exchange 2007</category><category domain="http://blogs.technet.com/benw/archive/tags/Powershell/default.aspx">Powershell</category></item></channel></rss>