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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23700676/viewspace-1052328/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值