¡m¤À¨É¡nPowershell±Ò¥ÎOU¤¤ªº¨Ï¥ÎªÌ¤Î¸s²Õmail¥\¯à | |
¾Þ§@Àô¹Ò
ºô°ì¡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ÅÞ¿è
- ³z¹LADSI¨ú±oOUª«¥ó¡A³v¤@§PÂ_OUª«¥ó¤¤ªº¤lª«¥ó¬°¨Ï¥ÎªÌ©Î¸s²Õ¡A¦A¤À§O³B²z¡C
- Y¤lª«¥ó¬°¨Ï¥ÎªÌ¡A¨Ì±b¸¹±Ò¥Î»P§_¤Îmail¥\¯à±Ò¥Î»P§_¡A¶i¦æ¹ïÀ³³B²z¡C
- Y¤lª«¥ó¬°¸s²Õ¡A¨Ì¸s²Õmail¥\¯à±Ò¥Î»P§_¡A¶i¦æ¹ïÀ³³B²z¡C
- ¬°ÁקK¸s²Õ¤¤¤å¦WºÙ¼vÅTemail address¤§«Ø¥ß¡A³z¹L¤¬°Ê¿é¤J¡AÅý¾Þ§@ªÌ¿é¤J¸s²ÕªºAlias¡A°µ¬°email«Ø¥ß¨Ì¾Ú¡C
- 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!
|