Exchange 2010 Powershell指令碼攻略(一)
AddReplicaToPFRecursive
Param(
[string] $Server,
[string] $TopPublicFolder = "",
[string] $ServerToAdd = ""
)
# This function validates the scripts parameters
function ValidateParams
{
$validInputs = $true
$errorString = ""
if ($TopPublicFolder -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The -TopPublicFolder parameter is required. Please pass in a valid Public Folder path, name, or entryID."
}
if ($ServerToAdd -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The -ServerToAdd parameter is required. Please pass in a valid mailbox server identity"
}
if (!$validInputs)
{
Write-error "$errorString"
}
return $validInputs
}
# Function that returns true if the incoming argument is a help request
function IsHelpRequest
{
param($argument)
return ($argument -eq "-?" -or $argument -eq "-help");
}
# Function that displays the help related to this script following
# the same format provided by get-help or
function Usage
{
@"
NAME:
`tAddReplicaToPFRecursive.ps1
SYNOPSIS:
`tAdds a new server to the replica list for a public folder, and all the
`tcontained folders under it. If the server is already listed in the
`treplica list for a particular folder, nothing is changed for that folder.
SYNTAX:
`tAddReplicaToPFRecursive.ps1
`t`t[-Server
`t`t[-TopPublicFolder
`t`t[-ServerToAdd
PARAMETERS:
`t-Server (optional)
`t`tThe server to operate against. Must be an Exchange 2007 Mailbox server
`t`twith a public folder database. Defaults to a convenient server.
`t-TopPublicFolder (required)
`t`tThe folder identity of the top of the tree of folders to modify
`t-ServerToAdd (required)
`t`tThe server identity to add to the replica list. Must be a server with a
`t`tpublic folder database.
`t-------------------------- EXAMPLE 1 --------------------------
C:PS> .AddReplicaToPFRecursive.ps1 -TopPublicFolder "Folder" -ServerToAdd "MyEx2003Server"
`t-------------------------- EXAMPLE 2 --------------------------
C:PS> .AddReplicaToPFRecursive.ps1 -Server "MyEx2007Server" -TopPublicFolder "Folder" -ServerToAdd "MyEx2003Server"
REMARKS:
`tReplica lists are updated quickly, but data replication can take a
`tsubstantial amount of time. The server being added will not show
`tcontent for some time.
RELATED LINKS:
`tAddReplicaToPFRecursive.ps1
`tMoveAllReplicas.ps1
`tRemoveReplicaFromPFRecursive.ps1
`tReplaceReplicaOnPFRecursive.ps1
`tGet-Help
"@
}
####################################################################################################
# Script starts here
####################################################################################################
# Check for Usage Statement Request
$args | foreach { if (IsHelpRequest $_) { Usage; exit; } }
# Validate the parameters
$ifValidParams = ValidateParams;
if (!$ifValidParams) { exit; }
$db = Get-PublicFolderDatabase -Server $ServerToAdd -ErrorAction Stop
if ($server)
{
$getpfcmd = "Get-PublicFolder -Server $Server -identity ""$TopPublicFolder"" -Recurse -ResultSize Unlimited"
}
else
{
$getpfcmd = "Get-PublicFolder -Identity ""$TopPublicFolder"" -Recurse -ResultSize Unlimited"
}
# These folders are not supposed to have any replica list,
# and attempts to change the replica list on any of them
# will result in an error. We'll just skip over these in the
# loop and avoid any unpleasantries.
$ExcludedFolders = new-object System.Collections.ArrayList
[void]$ExcludedFolders.Add("")
[void]$ExcludedFolders.Add("NON_IPM_SUBTREE")
[void]$ExcludedFolders.Add("NON_IPM_SUBTREESCHEDULE+ FREE BUSY")
[void]$ExcludedFolders.Add("NON_IPM_SUBTREEOFFLINE ADDRESS BOOK")
[void]$ExcludedFolders.Add("NON_IPM_SUBTREEEFORMS REGISTRY")
# The cast to [void] is to ignore the result of the Add method,
# which normally returns an int value. This int value is output to the
# console and is of no interest to anybody.
$pfsToChange = new-object System.Collections.ArrayList
invoke-expression $getpfcmd | foreach {
$OriginatingServer = $_.OriginatingServer
if (!$ExcludedFolders.Contains($_.Identity.ToString())) {
if (!$_.Replicas.Contains($db.Identity)) {
[void]$pfsToChange.Add($_.Identity)
}
}
}
$pfsToChange | foreach {
$pf = Get-publicfolder $_ -Server $OriginatingServer
$pf.Replicas += $db.Identity
Set-PublicFolder -Server $OriginatingServer -Identity $_ -Replicas $pf.Replicas
}
[@more@]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23700676/viewspace-1052327/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Exchange 2010 Powershell指令碼攻略(十五)指令碼
- Exchange 2010 Powershell指令碼攻略(十四)指令碼
- Exchange 2010 Powershell指令碼攻略(十三)指令碼
- Exchange 2010 Powershell指令碼攻略(十二)指令碼
- Exchange 2010 Powershell指令碼攻略(十一)指令碼
- Exchange 2010 Powershell指令碼攻略(十)指令碼
- Exchange 2010 Powershell指令碼攻略(九)指令碼
- Exchange 2010 Powershell指令碼攻略(八)指令碼
- Exchange 2010 Powershell指令碼攻略(七)指令碼
- Exchange 2010 Powershell指令碼攻略(六)指令碼
- Exchange 2010 Powershell指令碼攻略(五)指令碼
- Exchange 2010 Powershell指令碼攻略(四)指令碼
- Exchange 2010 Powershell指令碼攻略(三)指令碼
- Exchange 2010 Powershell指令碼攻略(二)指令碼
- powershell指令碼指令碼
- PowerShell 指令碼中的密碼指令碼密碼
- PowerShell 指令碼執行策略指令碼
- powershell重新命名指令碼指令碼
- 最簡單的一個powershell的指令碼指令碼
- Exchange 2010搭建
- shell指令碼攻略--DNS正向解析一鍵部署指令碼DNS
- Bash指令碼debug攻略指令碼
- 開機自啟動Powershell指令碼指令碼
- linux shell 指令碼攻略筆記Linux指令碼筆記
- 【黑客基礎】Windows PowerShell 指令碼學習(上)黑客Windows指令碼
- Exchange 2010需要的網路埠
- 微軟宣佈全新命令列+指令碼工具:PowerShell 7微軟命令列指令碼
- 五個實用的SQL Server PowerShell指令碼OMSQLServer指令碼
- 利用powershell指令碼Windows hosts記錄替換IP指令碼Windows
- Win10使用Powershell提示禁止執行指令碼怎麼辦 Win10使用Powershell提示禁止執行指令碼如何解決Win10指令碼
- 利用 Powershell 編寫簡單的瀏覽器指令碼瀏覽器指令碼
- 【連結】LINUX SHELL指令碼攻略筆記[速查]Linux指令碼筆記
- 《Linux Shell指令碼攻略(第2版)》書評Linux指令碼
- nuget打包檔案丟失如何使用powershell指令碼解決指令碼
- 使用VSCode遠端除錯惡意Powershell指令碼VSCode除錯指令碼
- 【VMware VCF】使用 PowerShell 指令碼管理 SDDC Manager 中的軟體包。指令碼
- PowerShell 指令碼來監控 CPU、記憶體和磁碟使用情況:指令碼記憶體
- linux shell 指令碼攻略學習6-xargs詳解Linux指令碼