Exchange 2010 Powershell指令碼攻略(二)
AddUsersToPFRecursive
Param(
[string] $Server,
[string] $TopPublicFolder = "",
[string] $User = "",
[string] $Permissions = ""
)
# 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 ($User -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The -User parameter is required. Please pass in a valid user name, email address or GUID"
}
if ($Permissions -eq "")
{
$validInputs = $false
$errorString += "`nMissing parameter: The -Permissions parameter is required. Please pass in a valid MAPI permission set"
}
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:
`tAddUsersToPFRecursive.ps1
SYNOPSIS:
`tAdds a specific user with specific permissions to the client
`tpermissions list for a public folder, and all the contained folders
`tunder it. If the user is already listed in the client permissions list
`tfor a particular folder, the user's permissions are updated to the new
`tspecified set.
SYNTAX:
`tAddUsersToPFRecursive.ps1
`t`t[-Server
`t`t[-TopPublicFolder
`t`t[-User
`t`t[-Permissions
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-User (required)
`t`tThe identity of the user to add to the client permissions.
`t-Permissions (required)
`t`tA MAPI client permission set
`t-------------------------- EXAMPLE 1 --------------------------
C:PS> .AddUsersToPFRecursive.ps1 -TopPublicFolder "Folder" -User "user" -Permissions {Reviewer,Owner}
`t-------------------------- EXAMPLE 2 --------------------------
C:PS> .AddUsersToPFRecursive.ps1 -Server "MyEx2007Server" -TopPublicFolder "Folder" -User "user" -Permission {Reviewer,Owner}
RELATED LINKS:
`tAddUsersToPFRecursive.ps1
`tRemoveUserFromPFRecursive.ps1
`tReplaceUserPermissionOnPFRecursive.ps1
`tReplaceUserWithUserOnPFRecursive.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; }
if ($server)
{
$getpfcmd = "get-publicfolder -server $Server -identity ""$TopPublicFolder"" -Recurse -resultsize unlimited"
}
else
{
$getpfcmd = "get-publicfolder -identity ""$TopPublicFolder"" -Recurse -resultsize unlimited"
}
# 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
[void]$pfsToChange.Add($_.Identity)
}
$pfsToChange | foreach {
$permission = get-PublicFolderClientPermission -identity $_ -user $User -erroraction Stop -server $OriginatingServer
if ($permission -ne $null) {
$permission | remove-PublicFolderClientPermission -identity $_ -server $OriginatingServer -Confirm:$false
}
add-PublicFolderClientPermission -identity $_ -user $user -AccessRights $Permissions -server $OriginatingServer;
}
[@more@]來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23700676/viewspace-1052328/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 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指令碼解決指令碼
- 快速掌握RabbitMQ(二)——四種Exchange介紹及程式碼演示MQ
- 【VMware VCF】使用 PowerShell 指令碼管理 SDDC Manager 中的軟體包。指令碼
- PowerShell 指令碼來監控 CPU、記憶體和磁碟使用情況:指令碼記憶體
- win10系統powershell指令恢復指令的操作方法Win10
- 要使用PowerShell命令將ESD映像轉換為FFU映像,您可以藉助dism.exe工具和PowerShell指令碼來完成指令碼
- Angular 4.0 內建指令全攻略Angular
- 【Azure Function App】Python Function呼叫Powershell指令碼在Azure上執行失敗的案例FunctionAPPPython指令碼
- powershell程式碼混淆繞過
- 【Azure Redis 快取】使用Python程式碼獲取Azure Redis的監控指標值 (含Powershell指令碼方式)Redis快取Python指標指令碼
- 【二分】[USACO 2010 Feb S]Chocolate Eating
- Powershell tricks::Powershell RemotingREM
- Powershell————1、認識Powershell
- 建立批次AD域使用者的指令碼可以使用 PowerShell 來實現。以下是一個簡單的示例指令碼,用於批次建立使用者:指令碼
- Powershell————2、Powershell互動式
- powershell各種反彈姿勢以及取證(二)
- Exchange Online Mailbox RestorationAIREST
- 【VMware vSphere】使用RVTools中的PowerShell指令碼建立匯出vSphere環境資訊的自動化任務。指令碼
- rust學習二、入門之執行單個指令碼Rust指令碼
- Python 處理指令碼的命令列引數(二):使用clickPython指令碼命令列
- 常用指令碼學習手冊——Bat指令碼指令碼BAT
- iOS逆向 Shell指令碼+指令碼重簽名iOS指令碼
- bzoj1816: [Cqoi2010]撲克牌(二分)
- shell指令碼指令碼
- MySQL指令碼MySql指令碼
- jpsall指令碼指令碼
- perl指令碼指令碼
- JMeter指令碼JMeter指令碼