Exchange 2010 Powershell指令碼攻略(三)
AggregatePFData
Param(
[string] $PublicFolder,
[string] $Server
)
$script:SkipCount = 0
$script:SkippedString = ""
# Function that dumps aggregated information from various pf cmdlets
function dump-pf($pf, $TargetServer)
{
# We don't care about the IPM root
if ($pf.Identity.ToString() -ne "")
{
$HasReplica = $False
if ($TargetServer)
{
$Server = $TargetServer
$dbName = (get-publicfolderdatabase -Server $TargetServer).Name
$pf.Replicas | foreach-object { if ($_.Name -eq $dbName) { $HasReplica = $True } }
}
else
{
# We need to figure out where we can find a replica for this pf
$Server = (get-publicfolderdatabase $pf.Replicas[0]).Server
$HasReplica = $True
}
if ($HasReplica)
{
$pfStats = get-publicfolderstatistics $pf.Identity -server $Server
# Figure out who's the owner of this pf
$ipfOwner = 0
$pfOwnerString = ""
$pfOwners = Get-PublicFolderClientPermission $pf.Identity -server $Server | where {$_.AccessRights[0].ToString() -eq "Owner"}
$pfOwners | foreach-object { $pfOwnerString += $_.User; if ($ipfOwner -lt ($pfOwners.Count -1)) { $pfOwnerString += ", " } $ipfOwner = $ipfOwner + 1 }
# Remove duplicate item types.
$pfItemTypes = get-publicfolderItemStatistics $pf.Identity -server $Server | sort-object -Property ItemType -Unique
# Convert the list of ItemTypes into a comma separated string
$ipfItemType = 0
$pfItemTypesString = ""
$pfItemTypes | foreach-object { $pfItemTypesString += $_.ItemType; if ($ipfItemType -lt ($pfItemTypes.Count - 1)) { $pfItemTypesString += ", " } $ipfItemType = $ipfItemType + 1 }
# Create a result object to return to the pipeline
$configEntry = new-object System.Management.Automation.PSObject;
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:Identity -value:$pf.Identity
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:Owner -value:$pfOwnerString
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:ItemTypes -value:$pfItemTypesString
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:FolderType -value:$pf.FolderType
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:MailEnabled -value:$pf.MailEnabled
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:HasModerator -value:$pf.HasModerator
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:HasRules -value:$pf.HasRules
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:ItemCount -value:$pfStats.ItemCount
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:TotalItemSize -value:$pfStats.TotalItemSize
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:LastUserAccessTime -value:$pfStats.LastUserAccessTime
add-member -InputObject:$configEntry -MemberType:NoteProperty -Name:LastUserModificationTime -value:$pfStats.LastUserModificationTime
write-output $configEntry
}
# If there's no replica, just skip this folder
# and let the user know we skipped some.
else
{
if ($script:SkipCount -ge 25)
{
if ($script:SkipCount -eq 25)
{
$script:SkippedString += ", ..."
}
}
else
{
if ($script:SkipCount -gt 0)
{
$script:SkippedString += ", "
}
$script:SkippedString += $pf.Identity.ToString()
}
$script:SkipCount = $script:SkipCount + 1
}
}
}
# 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:
`tAggregatePFData.ps1
SYNOPSIS:
`tCrawls to the public folder hierarchy and displays usage information
`tabout each folder.
SYNTAX:
`tAggregatePFData.ps1
`t`t[-PublicFolder
`t`t[-Server
PARAMETERS:
`t-PublicFolder (optional)
`t`tThe folder identity of the public folder to operate against. If none
`t`tspecified, then all the folders in the hierarchy are returned.
`t-Server (optional)
`t`tThe server to operate against. Must be an Exchange 2007 or later Mailbox
`t`tserver with a public folder database. Defaults to a convenient server.
`t-------------------------- EXAMPLE 1 --------------------------
C:PS> .AggregatePFData.ps1 -PublicFolder PF1
`t-------------------------- EXAMPLE 2 --------------------------
C:PS> .AggregatePFData.ps1 -PublicFolder PF1 -Server Server1
"@
}
####################################################################################################
# Script starts here
####################################################################################################
# Check for Usage Statement Request
$args | foreach { if (IsHelpRequest $_) { Usage; exit; } }
if ($PublicFolder)
{
if ($Server)
{
$pfs = get-publicfolder $PublicFolder -Server $Server
}
else
{
$pfs = get-publicfolder $PublicFolder
}
}
else
{
if ($Server)
{
$pfs = get-publicfolder "" -Server $Server -Recurse
}
else
{
# build a list of pfs in the org, use the pf dbs as a starting point and eliminate duplicate pfs
# do it in 2 steps because of remote powershell pipelining
$pfdbs = get-publicfolderdatabase
$pfdbs | foreach-object { $pfs += get-publicfolder "" -Server $_.Server -Recurse; $pfs = $pfs | Sort-Object -Property ParentPath,Name -Unique }
}
}
# now dump the information for each pf
$pfs | foreach-object { dump-pf -pf $_ -TargetServer $Server }
if ($script:SkipCount -gt 0)
{
Write-Warning "The following folders were skipped since they did not contain a replica on the server: "
Write-Warning $script:SkippedString
}
[@more@]Exchange 2010 Powershell指令碼攻略(一)來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23700676/viewspace-1052329/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- powershell指令碼指令碼
- powershell重新命名指令碼指令碼
- Bash指令碼debug攻略指令碼
- 【黑客基礎】Windows PowerShell 指令碼學習(上)黑客Windows指令碼
- 啟用或禁用普通使用者Exchange Online PowerShell功能
- 五個實用的SQL Server PowerShell指令碼OMSQLServer指令碼
- 使用VSCode遠端除錯惡意Powershell指令碼VSCode除錯指令碼
- Win10使用Powershell提示禁止執行指令碼怎麼辦 Win10使用Powershell提示禁止執行指令碼如何解決Win10指令碼
- 利用 Powershell 編寫簡單的瀏覽器指令碼瀏覽器指令碼
- 微軟宣佈全新命令列+指令碼工具:PowerShell 7微軟命令列指令碼
- shell指令碼攻略--DNS正向解析一鍵部署指令碼DNS
- nuget打包檔案丟失如何使用powershell指令碼解決指令碼
- 【VMware VCF】使用 PowerShell 指令碼管理 SDDC Manager 中的軟體包。指令碼
- Shell指令碼應用(三)指令碼
- PowerShell 指令碼來監控 CPU、記憶體和磁碟使用情況:指令碼記憶體
- 指令碼三兄弟 grep、awk、sed指令碼
- win10系統powershell指令恢復指令的操作方法Win10
- 要使用PowerShell命令將ESD映像轉換為FFU映像,您可以藉助dism.exe工具和PowerShell指令碼來完成指令碼
- Angular 4.0 內建指令全攻略Angular
- 【Azure Function App】Python Function呼叫Powershell指令碼在Azure上執行失敗的案例FunctionAPPPython指令碼
- powershell程式碼混淆繞過
- Linux學習之路(三)Shell指令碼初探Linux指令碼
- 【Azure Redis 快取】使用Python程式碼獲取Azure Redis的監控指標值 (含Powershell指令碼方式)Redis快取Python指標指令碼
- Powershell tricks::Powershell RemotingREM
- Powershell————1、認識Powershell
- Nifi元件指令碼開發—ExecuteScript 使用指南(三)Nifi元件指令碼
- RabbitMQ系列(三)RabbitMQ交換器Exchange介紹與實踐MQ
- 建立批次AD域使用者的指令碼可以使用 PowerShell 來實現。以下是一個簡單的示例指令碼,用於批次建立使用者:指令碼
- AngularJS 4(三)【指令】AngularJS
- Powershell————2、Powershell互動式
- shell指令碼的三種執行方式和區別指令碼
- 三、日常運維指令碼編寫一些技巧運維指令碼
- Linux中執行Shell指令碼的方式(三種方法)Linux指令碼
- Exchange Online Mailbox RestorationAIREST
- 【VMware vSphere】使用RVTools中的PowerShell指令碼建立匯出vSphere環境資訊的自動化任務。指令碼
- 常用指令碼學習手冊——Bat指令碼指令碼BAT
- iOS逆向 Shell指令碼+指令碼重簽名iOS指令碼
- 使用python指令碼傳遞引數:(三種方式可收藏)Python指令碼
- Python 處理指令碼的命令列引數(三):使用argparsePython指令碼命令列