Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a powershell cmdlet (move-IMAPMailboxToExchange) that requires a lot of repetition to enter. I want to call it with another batch/powershell script that just takes two args from the command line. I've tried every calling convention I can think of but I can't make it work.

I want this:

Move-IMAPMailboxToExchange -SourcePassword P@ssW0rd! -allowunsecureconnection -sourceLoginId username -sourceserver source.ser.ver -sourceidentity username@mail.dom.ain targetclientaccessserver "client.access.ser.ver" -targetidentity username@mail.dom.ain -verbose

To be this:

migrate-user username P@ssW0rd!

I've tried $args, but that seems to expand. I've tried $args[0] which works in the bareword password and sourcelogin, but doesn't work next to the @mail.... I've tried %1, etc, from the old DOS days but that doesn't work.

I'm a unix dork and I'm not quite grokking powershell yet.

share|improve this question
up vote 2 down vote accepted

From what I remember, single-quotes is how PowerShell designates something as 'do not parse'. so...

You might want to do something like this


Move-IMAPMailboxToExchange [all that jazz]

As a way to firmly declare the variables within the context of the script. If you're having trouble constructing the -sourceidentity and -targetidentity variables, you may want to pre-construct them before putting them on the move-imaptoexchange command...

share|improve this answer
Beautiful, thanks! It correctly interpolated the variable next to the @ sign so I didn't need to make temp variables for that. – Jim Zajkowski Jun 5 '09 at 15:19

You should be able to define a function or script file around your cmdlet, like this:

    function migrate-user

Move-IMAPMailboxToExchange -SourcePassword $password -allowunsecureconnection -sourceLoginId $username -sourceserver 'source.ser.ver' -sourceidentity "$username`@mail.dom.ain" targetclientaccessserver 'client.access.ser.ver' -targetidentity "$username`@mail.dom.ain" -verbose

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.