切换到宽版
  • 5634阅读
  • 1回复

[求助]使用脚本控制传输角色数据 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-03-21
— 本帖被 YOYO 从 Exchange 脚本中心 移动到本区(2015-06-25) —
  • 脚本环境:PowerShell
  • 适合版本:Exchange 2007
  • 适用平台:
To run the script, follow these steps:
1. Save this script on your Exchange server. Make sure the server you save it on is domain-joined.
2. Open up PowerShell, navigate to the folder that contains TransportRuleUsage.ps1, and run the following command:
PS> .\TransportRuleUsage.ps1
3. Send the output (TransportRuleOutput.txt) to benneu AT microsoft DOT com.



#################################################################################
#
# The sample scripts are not supported under any Microsoft standard support
# program or service. The sample scripts are provided AS IS without warranty
# of any kind. Microsoft further disclaims all implied warranties including, without
# limitation, any implied warranties of merchantability or of fitness for a particular
# purpose. The entire risk arising out of the use or performance of the sample scripts
# and documentation remains with you. In no event shall Microsoft, its authors, or
# anyone else involved in the creation, production, or delivery of the scripts be liable
# for any damages whatsoever (including, without limitation, damages for loss of business
# profits, business interruption, loss of business information, or other pecuniary loss)
# arising out of the use of or inability to use the sample scripts or documentation,
# even if Microsoft has been advised of the possibility of such damages
#
#################################################################################

#TransportRuleUsage.ps1
#This script takes a simple count of the types of conditions,
#actions, and exceptions your organization uses in its Transport Rules.
#
#We ask that you run this script and then send the results (in the
#file TransportRuleOutput.txt) to benneu@microsoft.com. We are
#re-designing the Transport Rules GUI and this data will assist us
#in making the GUI more usable.
#
#This script does not record any specifics about your Transport Rules,
#it just counts the conditions, actions, and exceptions that you have used.
#The $Rules variable holds a list of your Transport Rules
$Rules = Get-TransportRule
#The $Rule_Construction hashtable holds a count of the number of
#Conditions, Actions, and Exceptions you use in your Transport rules.
# For example: One rule with 1 Condition - 1 Action, two rules with
#2 conditions - 1 action, etc.
$Rule_Construction = @{}
#The $Action_Counts hashtable will hold a count of the
#Conditions used in your Transport Rules
$Action_Counts = @{}
#The $Condition_Counts hashtable will hold a count of the
#Conditions used in your Transport Rules
$Condition_Counts = @{}
#The $Exceptions_Counts hashtable will hold a count of the
#Exceptions used in your Transport Rules
$Exception_Counts = @{}

#Count the usage of conditions, actions, and exceptions
#in your Transport Rules
foreach ($Rule in $Rules)
{
    #Count the number of conditions, actions, and exceptions in the rule
    #and append to the $Rule_Summary string
    $Rule_Summary = ""
    if($Rule.conditions)
    {
$Rule_Summary += "Conditions: " + [string]$Rule.conditions.count
    }
    if($Rule.actions)
    {
$Rule_Summary += " Actions: " + [string]$Rule.actions.count
    }
    if($Rule.exceptions)
    {
$Rule_Summary += " Exceptions: " + [string]$Rule.exceptions.count
    }
    #Add $Rule_Summary to the hashtable if it is not there yet, or increment
    #the value of $Rule_Summary by 1
    $Rule_Construction[$Rule_Summary] += 1
    #Counts the Actions and store the counts in $Action_Counts
    if($Rule.actions)
    {
        foreach ($Action in $Rule.actions)
        {
     $Action_Counts[$Action.name] += 1
        }
    }
    #Counts the Conditions and store the counts in $Conditions_Counts
    if($Rule.conditions)
    {
        foreach ($Condition in $Rule.conditions)
        {
     $Condition_Counts[$Condition.name] += 1
        }
    }
    #Counts the Exceptions and store the counts in $Exceptions_Counts
    if($Rule.exceptions)
    {
        foreach ($Exception in $Rule.exceptions)
        {
     $Exception_Counts[$Exception.name] += 1
        }
    }
}
#Output counts of Actions, COnditions, and Exceptions to a file
#called TransportRuleOutput.txt
#Create file or clear file of any exiting data
Out-File -filepath TransportRuleOutput.txt
"Actions" | Out-File -append -filepath TransportRuleOutput.txt
foreach ($Action in $Action_Counts)
{
    $Action | out-file -append -filepath TransportRuleOutput.txt
}
"Conditions" | Out-File -append -filepath TransportRuleOutput.txt
foreach ($Condition in $Condition_Counts)
{
    $Condition | out-file -append -filepath TransportRuleOutput.txt
}
"Exceptions" | Out-File -append -filepath TransportRuleOutput.txt
foreach ($Exception in $Exception_Counts)
{
    $Exception | out-file -append -filepath TransportRuleOutput.txt
}
"Condition-Action-Exception Construction" | out-file -append -filepath TransportRuleUsage.txt
foreach ($Entry in $Rule_Construction)
{
    $Entry | fl | out-file -append -filepath TransportRuleOutput.txt
}
#Tell user the script has succeeded and remind them to send their results
#to benneu@microsoft.com
Write-Host "The script has run successfully.
Please check the results in TransportRuleOutput.txt.
Please send TransportRuleOutput.txt to benneu@microsoft.com.
Thank you for your help!
"

分享到
只看该作者 1楼  发表于: 2011-05-20
这么强,支持楼主,佩服
快速回复
限60 字节
 
上一个 下一个