Sunday, April 26, 2020

Corrections to 20345-1A demos module 4

 

 

Demonstration Steps

1.      On LON-EX1, open Windows PowerShell ISE as an administrator.

2.      Open C:\Labfiles\Mod04\Democode\Lesson01Demo-ManagingRecipients.ps1, and then follow the instructions.

Lesson02Demo-ManagingExchange.ps1

Lesson02Demo-MonitoringExchange.ps1

 replace line 63 with

get-message

remove-message -identity

use the identity from the get message e.g. LON-EX1\Unreachable\68719476771

Lesson03Demo-ProvisioningSetup.ps1

 

Abigail Rees managers

Ada Russell marketing

Beth Burke it

if ($User.Department -eq 'Marketing') {

    $Database = ' Marketing '

} elseif ($User.Department -eq 'IT') {

    $Database = ' IT '

} else {

    $Database = 'Managers'

}

Lesson01Demo-UsingSwitchStatements.ps1

"IT","Managers", "Marketing" | % {

    New-MailboxDatabase -Server LON-EX1 -Name $_

    Mount-Database $_

}

Restart-Service MSExchangeIS

# Get a collection of users who do not currently have mailboxes

$depts = @('IT','Managers','Marketing')

$adusers = Get-User -RecipientTypeDetails User

 

# Loop through user collection using foreach

foreach ($aduser in $adusers) {

    Write-Host "Processing user '$($aduser.Name)' in department '$($aduser.Department)'"

    # Switch on Department - note that switch can match multiple conditions unless we explicitly use a 'break' statement

    switch ($aduser.Department) {

        {$_ -in $depts} {

            # Users in these departments require a mailbox, so we need to enable them in the database that matches their department name

            $mbx = $aduser | Enable-Mailbox -Database $($aduser.Department)

            # Send each new mailbox a welcome e-mail

            Send-MailMessage -SmtpServer 'lon-ex1.adatum.com' -Port 25 -From 'administrator@adatum.com' -To $($mbx.WindowsEmailAddress) -Subject 'Welcome to Adatum!' -Body 'Enjoy your new Exchange Server 2016 mailbox'

        }

        'Managers' {

            # Managers also require that the new mailbox is excluded from DatabaseQuotaDefaults and need an Unlimited ProhibitSendReceiveQuota

            $aduser | Set-Mailbox -UseDatabaseQuotaDefaults $false -ProhibitSendReceiveQuota 'Unlimited' | Out-Null

        }

        'IT' {

            # IT Users also require an online archive mailbox with retention policy applied

            $aduser | Enable-Mailbox -Archive | Out-Null

            $aduser | Set-Mailbox -RetentionPolicy 'Default MRM Policy' | Out-Null

        }

    }

}




 

Smaller Demos

r:\Labfiles\Mod04\Democode\Lesson01Demo-Formatting.ps1.

Replace step 7 with:

#-----

# Example #7 - Show how using the -Auto switch will size output

#-----

Get-Mailbox | Format-Table

Get-Mailbox | Format-Table -Autosize

 

C:\Labfiles\Mod04\Democode\Lesson01Demo-UsingIfStatements.ps1

Replace lines 43 to 48 with

if ($User.Department -eq 'Marketing') {$Database = 'Marketing'elseif ($User.Department -eq 'IT') {$Database = 'IT'} else {$Database = 'Managers'}

Write-Output "$($User.Name) should be on mailbox database '$($Database)'"


Test with

Abigail Rees managers

Ada Russell marketing

Beth Burke it

C:\Labfiles\Mod04\Democode\Lesson01Demo-UsingSwitchStatements.ps1


Replace lines 43 to 47 with


switch ($User.Department) {

    'Marketing' {$Database = 'Marketing'}

    'IT' {$Database = 'IT'}

    default {$Database = 'Managers'}

}


C:\Labfiles\Mod04\Democode\Lesson01Demo-UsingLoops.ps1

 

C:\Labfiles\Mod04\Democode\Lesson01Demo-Filtering.ps1