Powershell cmdlet 단순화

Powershell cmdlet 단순화

입력하는 데 많은 반복이 필요한 powershell cmdlet(move-IMAPMailboxToExchange)이 있습니다. 명령줄에서 두 개의 인수만 가져오는 다른 배치/Powershell 스크립트를 사용하여 호출하고 싶습니다. 제가 생각할 수 있는 모든 호출 규칙을 시도해 보았으나 제대로 작동하지 않습니다.

나는 이것을 원한다:

Move-IMAPMailboxToExchange -SourcePassword P@ssW0rd! -allowunsecureconnection -sourceLoginId username -sourceserver source.ser.ver -sourceidentity [email protected] targetclientaccessserver "client.access.ser.ver" -targetidentity [email protected] -verbose

이렇게 하려면:

migrate-user username P@ssW0rd!

$args를 시도했지만 확장된 것 같습니다. 베어워드 비밀번호와 sourcelogin에서 작동하는 $args[0]를 시도했지만 @mail 옆에서는 작동하지 않습니다.... 예전 DOS 시절 %1 등을 시도했지만 그렇지 않습니다. 일하지 마세요.

나는 유닉스 바보이고 아직 Powershell을 잘 다루지 않습니다.

답변1

내가 기억하는 바에 따르면 작은따옴표는 PowerShell이 ​​무언가를 '구문 분석하지 않음'으로 지정하는 방식입니다. 그래서...

당신은 이런 일을하고 싶을 수도 있습니다

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

Move-IMAPMailboxToExchange [all that jazz]

스크립트 컨텍스트 내에서 변수를 확실하게 선언하는 방법입니다. -sourceidentity 및 -targetidentity 변수를 구성하는 데 문제가 있는 경우 move-imaptoexchange 명령에 넣기 전에 변수를 미리 구성할 수 있습니다.

$sourceident="$username"+'@srcmail.dom.ain'
$targeditent="$username"+'@tgtmail.dom.ain'

답변2

다음과 같이 cmdlet 주위에 함수 또는 스크립트 파일을 정의할 수 있어야 합니다.

    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

}

관련 정보