2

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.

2

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

You might want to do something like this

$username=$args[0]
$passwd=$args[1]

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...

$sourceident="$username"+'@srcmail.dom.ain'
$targeditent="$username"+'@tgtmail.dom.ain'
| 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
0

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

    function migrate-user
{
 param($username,$password)

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

}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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