# Sample Code used to create Teams Policies for Schools
# Andrew Sharrad 28/08/2021 v1.01

$UserName = "globaladmin@myschool.org.uk"
$Password = "Password99!"

$OnMicrosoftCOMPrefix="myschool"
#Example OnMicrosoftCOMPrefix=ourtenancyname (without the onmicrosoft.com suffix)

$CreatePrimaryPolicy = $true
$PrimaryPolicyName= "Stone_EduPrimary"

$CreateSecondaryPolicy = $true
$SecondaryPolicyName= "Stone_EduSecondary"

$CreateSixthFormPolicy = $true
$SixthFormPolicyName= "Stone_EduSixth"

$CreateTeacherPolicy = $true
$TeacherPolicyName= "Stone_EduTeacher"

# Change the below setting to $true if you have installed and want to use the Skype for Business Powershell Module
# https://www.microsoft.com/en-gb/download/details.aspx?id=39366


# Do not edit the lines below 

$GAPassSec = ConvertTo-SecureString -AsPlainText $Password -Force
$GACreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName,$GAPassSec


# Connected to MSTeams
Install-Module MicrosoftTeams -SkipPublisherCheck -AllowClobber
Connect-MicrosoftTeams -Credential $GACreds


if ($CreatePrimaryPolicy -eq $true) {

    $PolicyID = $PrimaryPolicyName

    Write-Host "Creating Primary School Policies"

    New-CsTeamsMessagingPolicy -Identity $PolicyID -AllowOwnerDeleteMessage $true -AllowUserDeleteMessage $false -AllowUserEditMessage $true `
        -ReadReceiptsEnabledType Everyone -AllowUserChat $false -AllowGiphy $false -GiphyRatingType Strict -AllowMemes $false -AllowStickers $true `
        -AllowUrlPreviews $true -AllowUserTranslation $true -AllowImmersiveReader $true -AllowPriorityMessages $false -AudioMessageEnabledType Disabled `
        -AllowRemoveUser $false -ChannelsInChatListEnabledType DisabledUserOverride -Description "Messaging Policy for Primary School Children"


    New-CsTeamsMeetingPolicy -Identity $PolicyID -AllowMeetNow $false -AllowOutlookAddIn $false -AllowChannelMeetingScheduling $false -AllowPrivateMeetingScheduling $false `
        -AllowTranscription $true -AllowCloudRecording $false -AllowIPVideo $true -MediaBitRateKb 50000 `
        -ScreenSharingMode SingleApplication -AllowParticipantGiveRequestControl $false -AllowExternalParticipantGiveRequestControl $false -AllowPowerPointSharing $true `
        -AllowWhiteboard $true -AllowSharedNotes $false `
        -AllowAnonymousUsersToStartMeeting $false -AutoAdmittedUsers EveryoneInCompany -AllowPSTNUsersToBypassLobby $false -AllowPrivateMeetNow $false `
        -LiveCaptionsEnabledType DisabledUserOverride -MeetingChatEnabledType Enabled -Description "Meeting Policy for Primary School Children"


    New-CsTeamsAppSetupPolicy -Identity $PolicyID -AllowSideLoading $false -AllowUserPinning $false -Description "AppSetup Policy for Primary School Children"


    New-CsTeamsCallingPolicy -Identity $PolicyID -AllowPrivateCalling $false -AllowCallForwardingToUser $false -AllowCallForwardingToPhone $false -AllowVoicemail AlwaysDisabled `
        -AllowCallGroups $false -AllowDelegation $false -PreventTollBypass $false -BusyOnBusyEnabledType Disabled -AllowWebPSTNCalling $false `
        -Description "Calling Policy for Primary School Children"


    New-CsTeamsMeetingBroadcastPolicy -Identity $PolicyID -AllowBroadcastScheduling $false -AllowBroadcastTranscription $true -BroadcastAttendeeVisibilityMode EveryoneInCompany `
        -BroadcastRecordingMode UserOverride -Description "Broadcast meeting policy for Primary School Children"


    New-CsTeamsChannelsPolicy -Identity $PolicyID -AllowPrivateChannelCreation $false -Description "Teams Policy for Primary School Children"

    Write-Host "Primary School policies created"


}



if ($CreateSecondaryPolicy -eq $true) {

    $PolicyID = $SecondaryPolicyName

    Write-Host "Creating Secondary School Policies"

    New-CsTeamsMessagingPolicy -Identity $PolicyID -AllowOwnerDeleteMessage $true -AllowUserDeleteMessage $false -AllowUserEditMessage $true `
        -ReadReceiptsEnabledType Everyone -AllowUserChat $false -AllowGiphy $false -GiphyRatingType Strict -AllowMemes $false -AllowStickers $true `
        -AllowUrlPreviews $true -AllowUserTranslation $true -AllowImmersiveReader $true -AllowPriorityMessages $false -AudioMessageEnabledType Disabled `
        -AllowRemoveUser $false -ChannelsInChatListEnabledType DisabledUserOverride -Description "Messaging Policy for Secondary School Children"


    New-CsTeamsMeetingPolicy -Identity $PolicyID -AllowMeetNow $false -AllowOutlookAddIn $false -AllowChannelMeetingScheduling $false -AllowPrivateMeetingScheduling $false `
        -AllowTranscription $true -AllowCloudRecording $false -AllowIPVideo $true -MediaBitRateKb 50000 `
        -ScreenSharingMode SingleApplication -AllowParticipantGiveRequestControl $false -AllowExternalParticipantGiveRequestControl $false -AllowPowerPointSharing $true `
        -AllowWhiteboard $true -AllowSharedNotes $false `
        -AllowAnonymousUsersToStartMeeting $false -AutoAdmittedUsers EveryoneInCompany -AllowPSTNUsersToBypassLobby $false -AllowPrivateMeetNow $false `
        -LiveCaptionsEnabledType DisabledUserOverride -MeetingChatEnabledType Enabled -Description "Meeting Policy for Secondary School Children"


    New-CsTeamsAppSetupPolicy -Identity $PolicyID -AllowSideLoading $false -AllowUserPinning $false -Description "AppSetup Policy for Secondary School Children"


    New-CsTeamsCallingPolicy -Identity $PolicyID -AllowPrivateCalling $false -AllowCallForwardingToUser $false -AllowCallForwardingToPhone $false -AllowVoicemail AlwaysDisabled `
        -AllowCallGroups $false -AllowDelegation $false -PreventTollBypass $false -BusyOnBusyEnabledType Disabled -AllowWebPSTNCalling $false `
        -Description "Calling Policy for Secondary School Children"


    New-CsTeamsMeetingBroadcastPolicy -Identity $PolicyID -AllowBroadcastScheduling $false -AllowBroadcastTranscription $true -BroadcastAttendeeVisibilityMode EveryoneInCompany `
        -BroadcastRecordingMode UserOverride -Description "Broadcast meeting policy for Secondary School Children"


    New-CsTeamsChannelsPolicy -Identity $PolicyID -AllowPrivateChannelCreation $false -Description "Teams Policy for Secondary School Children"


    Write-Host "Secondary School policies created"

}



if ($CreateSixthFormPolicy -eq $true) {

    $PolicyID = $SixthFormPolicyName

    Write-Host "Creating Sixth Form Policies"

    New-CsTeamsMessagingPolicy -Identity $PolicyID -AllowOwnerDeleteMessage $true -AllowUserDeleteMessage $true -AllowUserEditMessage $true `
        -ReadReceiptsEnabledType Everyone -AllowUserChat $false -AllowGiphy $false -GiphyRatingType Strict -AllowMemes $false -AllowStickers $true `
        -AllowUrlPreviews $true -AllowUserTranslation $true -AllowImmersiveReader $true -AllowPriorityMessages $false -AudioMessageEnabledType Disabled `
        -AllowRemoveUser $false -ChannelsInChatListEnabledType DisabledUserOverride -Description "Messaging Policy for Sixth Form Students"


    New-CsTeamsMeetingPolicy -Identity $PolicyID -AllowMeetNow $false -AllowOutlookAddIn $false -AllowChannelMeetingScheduling $false -AllowPrivateMeetingScheduling $false `
        -AllowTranscription $true -AllowCloudRecording $false -AllowIPVideo $true -MediaBitRateKb 50000 `
        -ScreenSharingMode SingleApplication -AllowParticipantGiveRequestControl $true -AllowExternalParticipantGiveRequestControl $false -AllowPowerPointSharing $true `
        -AllowWhiteboard $true -AllowSharedNotes $false `
        -AllowAnonymousUsersToStartMeeting $false -AutoAdmittedUsers EveryoneInCompany -AllowPSTNUsersToBypassLobby $false -AllowPrivateMeetNow $false `
        -LiveCaptionsEnabledType DisabledUserOverride -MeetingChatEnabledType Enabled -Description "Meeting Policy for Sixth Form Students"


    New-CsTeamsAppSetupPolicy -Identity $PolicyID -AllowSideLoading $false -AllowUserPinning $true -Description "AppSetup Policy for Sixth Form Students"


    New-CsTeamsCallingPolicy -Identity $PolicyID -AllowPrivateCalling $false -AllowCallForwardingToUser $false -AllowCallForwardingToPhone $false -AllowVoicemail AlwaysDisabled `
        -AllowCallGroups $false -AllowDelegation $false -PreventTollBypass $false -BusyOnBusyEnabledType Disabled -AllowWebPSTNCalling $false `
        -Description "Calling Policy for Sixth Form Students"


    New-CsTeamsMeetingBroadcastPolicy -Identity $PolicyID -AllowBroadcastScheduling $false -AllowBroadcastTranscription $true -BroadcastAttendeeVisibilityMode EveryoneInCompany `
        -BroadcastRecordingMode UserOverride -Description "Broadcast meeting policy for Sixth Form Students"


    New-CsTeamsChannelsPolicy -Identity $PolicyID -AllowPrivateChannelCreation $false -Description "Teams Policy for Sixth Form Students"


    Write-Host "Sixth Form policies created"

}


if ($CreateTeacherPolicy -eq $true) {

    $PolicyID = $TeacherPolicyName

    Write-Host "Creating Teacher Policies"
    
    New-CsTeamsMessagingPolicy -Identity $PolicyID -AllowOwnerDeleteMessage $true -AllowUserDeleteMessage $true -AllowUserEditMessage $true `
        -ReadReceiptsEnabledType Everyone -AllowUserChat $true -AllowGiphy $true -GiphyRatingType Strict -AllowMemes $false -AllowStickers $true `
        -AllowUrlPreviews $true -AllowUserTranslation $true -AllowImmersiveReader $true -AllowPriorityMessages $true -AudioMessageEnabledType ChatsAndChannels `
        -allowRemoveUser $true -ChannelsInChatListEnabledType DisabledUserOverride -Description "Messaging Policy for Teachers"


    New-CsTeamsMeetingPolicy -Identity $PolicyID -AllowMeetNow $true -AllowOutlookAddIn $true -AllowChannelMeetingScheduling $true -AllowPrivateMeetingScheduling $true `
        -AllowTranscription $true -AllowCloudRecording $true -AllowIPVideo $true -MediaBitRateKb 50000 `
        -ScreenSharingMode EntireScreen -AllowParticipantGiveRequestControl $true -AllowExternalParticipantGiveRequestControl $true -AllowPowerPointSharing $true `
        -AllowWhiteboard $true -AllowSharedNotes $true `
        -AllowAnonymousUsersToStartMeeting $false -AutoAdmittedUsers EveryoneInCompany -AllowPSTNUsersToBypassLobby $false -AllowPrivateMeetNow $false `
        -LiveCaptionsEnabledType DisabledUserOverride -MeetingChatEnabledType Enabled -Description "Meeting Policy for Teachers"


    #Set-CsTeamsMeetingPolicy -Identity $PolicyID -AllowMeetNow $true -AllowOutlookAddIn $true -AllowChannelMeetingScheduling $true -AllowPrivateMeetingScheduling $true `
    #    -AllowTranscription $true -AllowCloudRecording $true -AllowIPVideo $true -MediaBitRateKb 50000 `
    #    -ScreenSharingMode EntireScreen -AllowParticipantGiveRequestControl $true -AllowExternalParticipantGiveRequestControl $true -AllowPowerPointSharing $true `
    #    -AllowWhiteboard $true -AllowSharedNotes $true `
    #    -AllowAnonymousUsersToStartMeeting $false -AutoAdmittedUsers EveryoneInCompany -AllowPSTNUsersToBypassLobby $false -AllowPrivateMeetNow $false `
    #    -LiveCaptionsEnabledType DisabledUserOverride -MeetingChatEnabledType Enabled -Description "Meeting Policy for Teachers"

    
    New-CsTeamsAppSetupPolicy -Identity $PolicyID -AllowSideLoading $false -AllowUserPinning $true -Description "AppSetup Policy for Teachers"


    New-CsTeamsCallingPolicy -Identity $PolicyID -AllowPrivateCalling $false -AllowCallForwardingToUser $false -AllowCallForwardingToPhone $false -AllowVoicemail AlwaysDisabled `
        -AllowCallGroups $false -AllowDelegation $false -PreventTollBypass $false -BusyOnBusyEnabledType Disabled -AllowWebPSTNCalling $true `
        -Description "Calling Policy for Teachers"


    New-CsTeamsMeetingBroadcastPolicy -Identity $PolicyID -AllowBroadcastScheduling $false -AllowBroadcastTranscription $true -BroadcastAttendeeVisibilityMode EveryoneInCompany `
        -BroadcastRecordingMode AlwaysEnabled -Description "Broadcast meeting policy for Teachers"


    New-CsTeamsChannelsPolicy -Identity $PolicyID -AllowPrivateChannelCreation $true -Description "Teams Policy for Teachers"

    Write-Host "Teacher policies created"

}