Posts Tagged ‘bulk’

Hi Folks,

today’s challenge was to bulk set calendar rights in a multilingual environment (with powershell).
On the net you can find some articles that address similar problems, but no real solution.

Download the follwing scripts as txt here.

Here my quick an dirty script:

# Set default as LimitedDetails for all calendars.
# Will get the language forch each users calendar Folder
# TEST WITH ONE ORE MORE USERS
# foreach($mbx in Get-Mailbox -identity USER | where-object {$_.displayname -like "*test user*"})


foreach($mbx in Get-Mailbox -ResultSize Unlimited | where-object {$_.displayname -notmatch "discovery"})

{
$Calfolder = $Mbx.Name
$Calfolder += ':\'
$CalFolder += [string](Get-mailboxfolderstatistics $Mbx -folderscope calendar).Name
$mbx = $CalFolder
$test = Get-MailboxFolderPermission -Identity $mbx -erroraction silentlycontinue
if($test -ne $null)
{
Set-MailboxFolderPermission -Identity $mbx -User Default -AccessRights LimitedDetails | out-null
}
}

If you want to create all new mailboxes with special permissions you nee to configure the Cmdlet Extension Agent
To enable the agent this you have to the following steps:

  • Create an XML file named ScriptingAgentConfig.xml  and save it in your Exchange’s Default Directory on EVERY Exchange Server in your organization
    e.g. C:\Program Files\Microsoft\Exchange Server\V15\Bin\CmdletExtensionAgents

    <?xml version=”1.0″ encoding=”utf-8″ ?>
    <Configuration version=”1.0″>

    <Feature Name=”MailboxProvisioning” Cmdlets=”New-Mailbox”>
    <ApiCall Name=”OnComplete”>
    if($succeeded)
    {
    start-sleep -s 10
    $mbx =  (Get-User $provisioningHandler.UserSpecifiedParameters[“Name”]).distinguishedName
    Set-MailboxFolderPermission -Identity $mbx”:\Calendar” -User “Default” -AccessRights LimitedDetails
    }
    </ApiCall>
    </Feature>

    <Feature Name=”MailboxProvisioning” Cmdlets=”Enable-Mailbox”>
    <ApiCall Name=”OnComplete”>
    if($succeeded)
    {
    start-sleep -s 5
    $user = Get-User -Identity $provisioningHandler.UserSpecifiedParameters[“Identity”]
    $mbx = Get-Mailbox -Identity $user.DistinguishedName
    Set-MailboxFolderPermission -Identity $mbx”:\Calendar” -User “Default” -AccessRights LimitedDetails
    }
    </ApiCall>
    </Feature>

    </Configuration>

 

  • Use the Exchange Management Shell and run the following command on EVERY Exchange server in your organization:
    Enable-CmdletExtensionAgent “Scripting Agent”
  • Create new user

Cheers,

Chris

Often you need to create some users for test purposes. Here you have a PowerShell script, which will do this procedure for you.

# Get domain and distinguished name
$Domain = (Get-ADDomain).distinguishedname

# Where to place the created users
$TargetOU = “Test”

# distinguished name for OrgUnit
$OUDN = “OU=$TargetOU,$Domain”

# How many users should be created
$NumberUsers= 50

# fill up description field with text and date
$Datetime = get-date -format G
$DField = “TEST ENVIRONMENT USER $datetime”

# OrgUnit check
$OU = Get-ADOrganizationalUnit -Filter { name -eq $TargetOU }
if($OU -eq $null)
{New-ADOrganizationalUnit -Name $TargetOU -Path $Domain}
else
{write-host “OU” $OU ” already there”}

# User creation

$u = 1
While ($u -le $usercount)
{
$UserName = “User” + $u
$UserDisplayName = “Testuser ” + $u
New-ADUser –Name $UserName –SamAccountName $UserName –DisplayName $UserDisplayName `
-Path $OUDN –Enabled $true –ChangePasswordAtLogon $true -description $DField `
-AccountPassword (ConvertTo-SecureString “YOUR_PASSWORD” -AsPlainText -force) -PassThru
$u = $u + 1
}

Cheers,

Chris