RSS

使用powershell来加速exchange 2007日常管理

10 Feb

我之前写过如何利用for循环来批量创建账户。今天的议题是如何利用powershell来加速你的日常管理。

1、创建邮箱

创建一个新的启动邮箱的用户。
new-Mailbox -alias testmbx -name TestMailbox -database "Mailbox Database" -org Users -UserPrincipalName testmbx@example.com
Password: <userpassword>
创建一个新的资源邮箱
new-Mailbox -alias testresmbx -name TestResourceMailbox -database "Mailbox Database" -org Users <-Room | -Equipment>  -UserPrincipalName testresourcembx@example.com
创建一个共享邮箱
new-Mailbox -alias testsharedmbx -name TestSharedMailbox -database "Mailbox Database" -org Users -shared -UserPrincipalName testsharedmbx@example.com
创建一个新的连接邮箱
new-Mailbox -alias testlinkedmbx -name TestLinkedMailbox -database "Mailbox Database" -org Users -LinkedMasterAccount account@userdomain.com -LinkedDomainController userdomain-dc-01 -UserPrincipalName testmbx@example.com

为已存在的用户启动用户邮箱
Enable-Mailbox logondisableduser -database "Mailbox Database"
为已存在的用户需要disabled ad账户启动资源邮箱
Enable-Mailbox logondisableduser <-Room | -Equipment> -database "Mailbox Database"
为已存在的用户需要disabled ad账户启动linked mailbox
Enable-Mailbox logondisableduser -database "Mailbox Database" -LinkedMasterAccount account@userdomain.com -LinkedDomainController userdomain-dc-01

2、进行move / Disable / Remove 邮箱操作

移动一个邮箱
Move-Mailbox testmbx -targetdatabase "Mailbox Database"
将一个服务器上的邮箱移动到目标邮箱数据库
Get-Mailbox -server testserver | Move-Mailbox -targetdatabase "Mailbox Database"
禁止一个邮箱
Disable-Mailbox testmbx
禁止一个服务器上所有的邮箱
Get-Mailbox -server testserver | Disable-Mailbox
删除一个启动邮箱的用户 (连同ad账户)
Remove-Mailbox testmbx
删除一个服务器上所有的用户
Get-Mailbox -server testserver | Remove-Mailbox

3、为一个邮箱设定storage quota
Set-Mailbox testmbx -UseDatabaseQuotaDefaults:$False -IssueWarningQuota 90MB -ProhibitSendQuota 95MB -ProhibitSendReceiveQuota 100MB

4、设定投递设置
Set-Mailbox testmbx -DeliverToMailboxAndForward:$True -ForwardingAddress jaredz@example.com -RecipientLimits 10

5、为邮箱添加一个新邮件地址:
$mbx = get-Mailbox testmbx;
$mbx.EmailAddresses += "newaddr@example.com";
$mbx | set-Mailbox

这里的修改受到收件人策略影响。你无法修改主要的smtp地址,或者删除其他email地址,但是你可以添加一个新地址。

6、控制邮箱权限:

授予 "Send on behalf"权限
Set-Mailbox testmbx -GrantSendOnBehalfTo jaredz
授予 "Send-As" 权限
Add-ADPermission testmbx -ExtendedRights Send-As -user jaredz
授予完全访问权限
Add-MailboxPermission testmbx -AccessRights FullAccess -user jaredz

7、控制邮箱的ActiveSync, OWA, MAPI, UM, IMAP and POP 功能

set-CASMailbox testmbx -MobileSyncEnabled:$True -OWAEnabled:$True -MAPIEnabled:$True -PopEnabled:$True -ImapEnabled:$True
Enable-UMMailbox testmbx -UMMailboxPolicy testumpolicy -Extensions 12345

8、设置邮箱使用的策略:

set-Mailbox testmbx -ManagedFolderMailboxPolicy "Inbox JunkEmail Policy" -RetentionHoldEnabled:$True -StartDateForRetentionHold "1/1/2009 2:37:06 AM" -EndDateForRetentionHold "1/1/2009 2:37:06 AM"

——————————

批量操作

1、使用csv来创建mailbox
Avalanche.csv的格式为Pos,No,Player,Age,Ht,Wt,Born,Exp,Birth City

$password = Read-Host "Enter password" –AsSecureString
import-csv Avalanche.csv | foreach {new-mailbox -alias "avalanche$($_.No)" -Name $_.Player -password $password -database "Mailbox Database" -org Users -UserPrincipalName "avalanche$($_.No)@example.com"}

2、批量创建一系列含有一个数据库的存储组

1..<nn> | foreach {new-StorageGroup SG_$_ -server <server> | new-MailboxDatabase MBDB}

3、批量在数据库中创建一系列邮箱

$password = Read-Host "Enter password" -AsSecureString
1..<nn> | foreach { new-Mailbox -alias "user$_" -name "User $_" -password $password -database "Mailbox Database" -org Users -UserPrincipalName "user$_@example.com" }

4、批量修改

修改所有邮箱的部门属性
Get-Mailbox | Set-User -department "New Dept"
将所有含有jared的用户名邮箱部门属性修改
Get-Mailbox *jared* | Set-User -department "New Dept"
将某个邮箱数据库中的邮箱部门属性修改:
Get-Mailbox -database "Mailbox Database" | Set-User -department "New Dept"
将某个office中的邮箱存储quota设置为1GB
$OfficeName = "Boston"
get-mailbox -filter {office -eq $OfficeName } | set-Mailbox -UseDatabaseQuotaDefaults:$false -IssueWarningQuota 800MB -ProhibitSendQuota 900MB -ProhibitSendReceiveQuota 1GB

5、报表:

将所有邮箱信息导出到一个csv文件
get-mailbox | export-csv export.csv

导出某个office中所有邮箱的quota
$OfficeName = "Boston"
get-mailbox -filter {Office -eq $OfficeName } | select name,office, *quota | sort name | export-csv export.csv

查看所有邮箱存储中的邮箱信息
get-MailboxStatistics | select DisplayName, TotalItemSize, TotalDeletedItemsize, DatabaseName | format-table

Advertisements
 
Leave a comment

Posted by on February 10, 2009 in Exchange Server

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: