Shunze ¾Ç¶é >¹q¸£¸ê°T¾Ç¨t >Exchange 2010 > ¡m¤À¨É¡nPowershell±Ò¥ÎOU¤¤ªº¨Ï¥ÎªÌ¤Î¸s²Õmail¥\¯à «¢Åo¡AÁÙ¨S¦³µù¥U©ÎªÌµn¤J¡C½Ð§A[µù¥U|µn¤J]
« ¤W¤@½g¥DÃD ¤U¤@½g¥DÃD » Åã¥Ü¦¨¦C¦L¼Ò¦¡ | ¼W¥[¨ì§Úªº³Ì·R
µoªí·s¥DÃD µoªí¦^ÂÐ
§@ªÌ
¥DÃD
shunze
¤u¤Í§B§B


µù¥U¤é´Á: 2002 04
¨Ó¦Û: ¼é¦Á²×¤î¤§¦a
¤å³¹: 2380

shunze Â÷½u
¡m¤À¨É¡nPowershell±Ò¥ÎOU¤¤ªº¨Ï¥ÎªÌ¤Î¸s²Õmail¥\¯à¤Þ¥Î¦^ÂÐ ½s¿è/§R°£¤å³¹ ·j´M¥Ñ  µoªíªº¨ä¥L¤å³¹ ¦^³øµ¹ª©¥D IP ¦ì¸m ¦^¦¹­¶³Ì¤W¤è

¾Þ§@Àô¹Ò
ºô°ì¡Gtest.com.tw
Domain Controller¡Gtest-AD.test.com.tw
Exchange Server¡GMail-Exchg2010.test.com.tw
Exchange Mail Database¡Gtestmailbox
OU¡GTest-OU
¨Ï¥ÎªÌ±b¸¹¡GShunzeA (mail¤w±Ò¥Î) ShunzeB (±b¸¹°±¥Î) ShunzeC (mail¥¼±Ò¥Î)
¸s²Õ±b¸¹¡GShunzeGP1 (mail¤w±Ò¥Î) ShunzeGP2 (mail¥¼±Ò¥Î)




³B²zÅÞ¿è

  1. ³z¹LADSI¨ú±oOUª«¥ó¡A³v¤@§PÂ_OUª«¥ó¤¤ªº¤lª«¥ó¬°¨Ï¥ÎªÌ©Î¸s²Õ¡A¦A¤À§O³B²z¡C
  2. ­Y¤lª«¥ó¬°¨Ï¥ÎªÌ¡A¨Ì±b¸¹±Ò¥Î»P§_¤Îmail¥\¯à±Ò¥Î»P§_¡A¶i¦æ¹ïÀ³³B²z¡C
  3. ­Y¤lª«¥ó¬°¸s²Õ¡A¨Ì¸s²Õmail¥\¯à±Ò¥Î»P§_¡A¶i¦æ¹ïÀ³³B²z¡C
  4. ¬°ÁקK¸s²Õ¤¤¤å¦WºÙ¼vÅTemail address¤§«Ø¥ß¡A³z¹L¤¬°Ê¿é¤J¡AÅý¾Þ§@ªÌ¿é¤J¸s²ÕªºAlias¡A°µ¬°email«Ø¥ß¨Ì¾Ú¡C
  5. ­Y¼È®É¤£·Q¬°¸s²Õ«Ø¥ßmail¥\¯à¡A¥iª½±µ©ó¿é¤J¤º®e«ö¤Uenter¡A²¤¹Lmail«Ø¥ß¥\¯à¡C


Script
$member=[ADSI]"LDAP://test-AD/OU=Test-OU,DC=test,DC=com,DC=tw"

# ¨Ï¥ÎªÌ±b¸¹±Ò¥Î»P§_ªº¼Æ­È°}¦C
$EnableNum ={512,544,66048,66080,262656,262688,328192,328224}
$DisableNum={514,546,66050,66082,262658,262690,328194,328226}

foreach ($item in $member.psbase.children) {
    if ($item.psbase.schemaclassname -eq "user") {
        # ª«¥ó¬° user ³B²zÅÞ¿è
        $user=$item.name
        $value= $item.useraccountcontrol
        $homeMDB=$item.homeMDB
        if ("$DisableNum".contains( $value )) {
            Write-Host "Account '$user' disabled"
        } elseif ( "$EnableNum".contains( $value )) {
            if ($homeMDB) {
                Write-Host "Acount '$user' mailbox exist!"
                Write-Host $homeMDB
            } else {    
                Write-Host "Enable $user MailBox..."
                Enable-Mailbox -Identity test\$user -Alias $user -Database "testmailbox" -DomainController "test-AD.test.com.tw" -Confirm
            }
        } else {
            Write-Host "Other Type account, useraccountcontrol value $value ."
        }
    } elseif ($item.psbase.schemaclassname -eq "group") {
        # ª«¥ó¬° group ³B²zÅÞ¿è
        $group=$item.name
        $legacyExchangeDN=$item.legacyExchangeDN
        if ($legacyExchangeDN) {
            Write-Host "Group '$group' mailbox exist!"
            Write-Host $legacyExchangeDN
        } else {
            $alias = Read-Host "Please input the email address alias for GROUP $group"
            if ($alias) {
                Enable-DistributionGroup -Identity test\$group -Alias $alias -DomainController "test-AD.test.com.tw" -Confirm
            } else {
                Write-Host "Failed to create group '$group' mailbox..."
            }
        }
    }
    Write-Host
}


«ü¥O½X²³æ»¡©ú¦p¤U
  • $member=[ADSI]¡§LDAP://test-AD/OU=Test-OU,DC=test,DC=com,DC=tw" ³z¹LADSI¨Ó¨ú±otest-AD.test.com.twºô°ìùتºOUª«¥óTest-OU¶°¦X¡C
  • $member.psbase.children ¨ú±oOU¤Uªº¤lª«¥ó¡A½Ñ¦p¨Ï¥ÎªÌ¡A¸s²Õ¡AÁpµ¸¤H...µ¥¡C
  • useraccountcontrol¡BhomeMDB Âǥѳo¨â­Ó¨Ï¥ÎªÌª«¥óÄݩʨӧPÂ_¨Ï¥ÎªÌ±b¸¹ªº±Ò¥Îª¬ºA»Pmail¥\¯à¡C¥¼«Ø¥ßmail¡AhomeMDB­È¬°null¡C
  • legacyExchangeDN ÂǥѦ¹ÄݩʨӧPÂ_¸s²Õmail¥\¯à¬O§_±Ò¥Î¡C¥¼±Ò¥Î¬°null­È¡C
  • -Alias ¸s²Õemail address²Õ¦X¦ÛAlias+ºô°ì¡C³z¹L¿é¤J¥\¯à¡AÅý¾Þ§@­û¿é¤J¸s²ÕªºAlias¡F¤£¿é¤J¡A°±¤î«Ø¥ß¸s²Õemail¡C


±NscriptÀx¦s¬°°ÆÀɦWps1ªºÀɮ׫á¡A°õ¦æ¦¹scriptµe­±Â^¹Ï¦p¤U¡G



UserAccountControl Value°Ñ¦Ò¸ê®Æ
Active Directory UserAccountControl Value



♥¶¶¤l¦Ñ±Cªººô©ç¡A½Ð¦hÃö·Ó¡ã

If you don't like something, change it.
If you can't change it, change your attitude.
Don't complain!




2014-01-27, 00:25 shunze ªº­Ó¤H¸ê®Æ §â shunze ¥[¤J¦n¤Í¦Cªí µo°eEmailµ¹ shunze ÂsÄý shunze ªººô¯¸ MSN : shunze@gmail.com
  « ¤W¤@½g¥DÃD ¤U¤@½g¥DÃD »
µoªí·s¥DÃD µoªí¦^ÂÐ
¸õ¨ì:

Powered by: Burning Board 1.1.1 2001 WoltLab GbR