From b15df2191aa13a774831decef2acab0c311c4491 Mon Sep 17 00:00:00 2001 From: Doli Geetha Sai Kumari <62688828+Geetha63@users.noreply.github.com> Date: Tue, 22 Jun 2021 18:10:23 +0530 Subject: [PATCH] Adding 3 scripts 1.Add Teachers to Distribution list-Education domain 2.AssignPolicyToTeachers-Education domain 3.User As Teams Owner --- .../AddTeacherToDl.ps1 | 43 +++++++++ .../README.md | 33 +++++++ .../AssignPolicyToTeachers.ps1 | 62 ++++++++++++ .../README.md | 96 +++++++++++++++++++ UserAsTeamsOwner/Readme.md | 62 ++++++++++++ UserAsTeamsOwner/UserAsTeamsOwner.ps1 | 51 ++++++++++ 6 files changed, 347 insertions(+) create mode 100644 AddTeacherToDistribution list-Education domain/AddTeacherToDl.ps1 create mode 100644 AddTeacherToDistribution list-Education domain/README.md create mode 100644 AssignPolicyToTeachers-EducationDomain/AssignPolicyToTeachers.ps1 create mode 100644 AssignPolicyToTeachers-EducationDomain/README.md create mode 100644 UserAsTeamsOwner/Readme.md create mode 100644 UserAsTeamsOwner/UserAsTeamsOwner.ps1 diff --git a/AddTeacherToDistribution list-Education domain/AddTeacherToDl.ps1 b/AddTeacherToDistribution list-Education domain/AddTeacherToDl.ps1 new file mode 100644 index 0000000..61ecaf0 --- /dev/null +++ b/AddTeacherToDistribution list-Education domain/AddTeacherToDl.ps1 @@ -0,0 +1,43 @@ +#Script will search and filter teachers in a tenant using license parameter and adds to the All teachers distribution list +$logfile = ".\log_$(get-date -format `"yyyyMMdd_hhmmsstt`").txt" +$start = [system.datetime]::Now + +If(Get-Module -ListAvailable -NameAzureAD) + { + Write-Host "AzureAD Already Installed" + } + else { + try { Install-Module -Name AzureAD + Write-Host "Installed AzureAD" + } + catch{ + $_.Exception.Message | out-file -Filepath $logfile -append + } + } + try{ + $credential= get-credential + Connect-AzureAD -Credential $credential + } + catch{ +$_.Exception.Message | out-file -Filepath $logfile -append +} +$group = Get-AzureADGroup -SearchString "all teachers" +$groupid = $group.objectid +try{ +$user = Get-AzureADUser -All $true | where {$_.AssignedLicenses -like "*94763226-9b3c-4e75-a931-5c89701abe66*"} +$userid = $user.objectid +foreach ($userid in $userid){ +Add-AzureADGroupMember -ObjectId $groupid -RefObjectId $userid +} +Get-AzureADSubscribedSku | ft *skupart*,*consu* +(Get-AzureADGroupMember -all $true -ObjectId $groupid).count +} + catch{ +$_.Exception.Message | out-file -Filepath $logfile -append +} + +$end = [system.datetime]::Now +$resultTime = $end - $start +Write-Host "Execution took : $($resultTime.TotalSeconds) seconds." -ForegroundColor Cyan + +#end of script diff --git a/AddTeacherToDistribution list-Education domain/README.md b/AddTeacherToDistribution list-Education domain/README.md new file mode 100644 index 0000000..879b4ab --- /dev/null +++ b/AddTeacherToDistribution list-Education domain/README.md @@ -0,0 +1,33 @@ +# Add Teachers to Distribution list-Education domain + +# Description + +Script will search and filter teachers in a tenant using license parameter and adds to the *All teachers* distribution list + +System should have the Azureadpreview module [`Install-Module AzureADPreview`](https://docs.microsoft.com/en-us/powershell/azure/active-directory/install-adv2?view=azureadps-2.0-preview#installing-the-azure-ad-module) to execute the script + +# Inputs +Global Administrator or Azure AD Administrator credentials + +# Prerequisites +As an Administrator, type PowerShell in the start menu + +Right-click Windows PowerShell, then select Run as Administrator. Click Yes at the UAC prompt + +1. Type the following within PowerShell and then press Enter: + + `Install-Module AzureAd` + +2. Type Y at the prompt.Press Enter + +3. If you are prompted for an untrusted repository, then type A (Yes to All) and press Enter. The module will now install + +# How to run the script +To run the script you will need to either download it or copy and paste the script into PowerShell + +Provide the global administrator credentials or AzureAD admin credentials when it prompts + +Hit enter to continue + +# Output +Script will provide the count of teachers who has the teacher license, count of teachers in DL and log file will be generated with exceptions, errors along with script execution time diff --git a/AssignPolicyToTeachers-EducationDomain/AssignPolicyToTeachers.ps1 b/AssignPolicyToTeachers-EducationDomain/AssignPolicyToTeachers.ps1 new file mode 100644 index 0000000..d0a6ed5 --- /dev/null +++ b/AssignPolicyToTeachers-EducationDomain/AssignPolicyToTeachers.ps1 @@ -0,0 +1,62 @@ +# This Script will search for All Teachers distribution list in tenant and assign policy types TeamsChannelsPolicy, TeamsMeetingPolicy, TeamsMessagingPolicy with policy name AllTeachers to All Teachers distribution list + +$logfile = ".\log_$(get-date -format `"yyyyMMdd_hhmmsstt`").txt" +$start = [system.datetime]::Now + + If(Get-Module -ListAvailable -Name MicrosoftTeams) + { + Write-Host "MicrosoftTeams Already Installed" + } + else { + try { Install-Module -Name MicrosoftTeams + Write-Host "Installed MicrosoftTeams" + } + catch{ + $_.Exception.Message | out-file -Filepath $logfile -append + }} + + If(Get-Module -ListAvailable -Name AzureAD) + { + Write-Host "AzureAD Already Installed" + } + else { + try { Install-Module -Name AzureAD + Write-Host "Installed AzureAD" + } + catch{ + $_.Exception.Message | out-file -Filepath $logfile -append + }} + + try{ + $credential= get-credential + }catch{ +$_.Exception.Message | out-file -Filepath $logfile -append +} +try{ +Connect-MicrosoftTeams -Credential $credential +}catch{ +$_.Exception.Message | out-file -Filepath $logfile -append +} +try{ +Connect-AzureAD -Credential $credential +} +catch{ +$_.Exception.Message | out-file -Filepath $logfile -append +} + + +$group = Get-AzureADGroup -SearchString "all teachers" +$groupid = $group.objectid +try{ +New-CsGroupPolicyAssignment -GroupId $groupid -PolicyType TeamsChannelsPolicy -PolicyName "AllTeachers" -Rank 1 +New-CsGroupPolicyAssignment -GroupId $groupid -PolicyType TeamsMeetingPolicy -PolicyName "AllTeachers" -Rank 1 +New-CsGroupPolicyAssignment -GroupId $groupid -PolicyType TeamsMessagingPolicy -PolicyName "AllTeachers" -Rank 1 +} +catch{ +$_.Exception.Message | out-file -Filepath $logfile -append +} + + +$end = [system.datetime]::Now +$resultTime = $end - $start +Write-Host "Execution took : $($resultTime.TotalSeconds) seconds." -ForegroundColor Cyan diff --git a/AssignPolicyToTeachers-EducationDomain/README.md b/AssignPolicyToTeachers-EducationDomain/README.md new file mode 100644 index 0000000..db8632f --- /dev/null +++ b/AssignPolicyToTeachers-EducationDomain/README.md @@ -0,0 +1,96 @@ +# AssignPolicyToTeachers-Education domain + +# Description +Script will search for **All Teachers** distribution list in tenant and assign policy types TeamsChannelsPolicy, TeamsMeetingPolicy, TeamsMessagingPolicy with policy name AllTeachers to **All Teachers** distribution list + +GroupPolicyAssignment is used to assign a policy to a security group or distribution list. The policy assignment will then be propagated to the members of the group (even if members are added to the group later) in accordance with the rules for group policy inheritance + +System should have the AzureADPreview module [`Install-Module AzureADPreview`](https://docs.microsoft.com/en-us/powershell/azure/active-directory/install-adv2?view=azureadps-2.0-preview#installing-the-azure-ad-module) and [`Install-Module MicrosoftTeams`](https://www.powershellgallery.com/packages/MicrosoftTeams/1.0.6) + +# Inputs +Global Administrator or AzureAD and MicrosoftTeams Administrator credentials + +# Parameters + +`-GroupId` + + The ID of a batch policy assignment operation + - - - + Type: String + - - - + Position: Named + - - - + Default value: None + - - - + Accept pipeline input: False + - - - + Accept wildcard characters: False + - - - + +`-PolicyName` + +The name of the policy to be assigned +- - - +Type: String + - - - +Position: Named +- - - +Default value: None +- - - +Accept pipeline input: False +- - - +Accept wildcard characters: False + +`-PolicyType` + +The type of the policy to be assigned +- - - +Type: String +- - - +Position: Named +- - - +Default value: None +- - - +Accept pipeline input: False +- - - +Accept wildcard characters: False + +`-Rank` + + The rank of the policy assignment, relative to other group policy assignments for the same policy type. + - - - + Type: String + - - - + Position: Named + - - - + Default value: None + - - - + Accept pipeline input: False + - - - + Accept wildcard characters: False + +# Prerequisites +As an Administrator, type PowerShell in the start menu + +Right-click on Windows PowerShell, then select run as Administrator. Click Yes at the UAC prompt. +1. Type the following within PowerShell and then press Enter: + + `Install-Module AzureAd` + +2. Type Y at the prompt. Press Enter + +3. If you are prompted for an untrusted repository, then type A (Yes to All) and press Enter. The module will now install + +4. Repeat steps 1 to 3 to install MicrosoftTeams module, cmdlet `Install-Module MicrosoftTeams` + +# How to run the script +To run the script you will need to either download it or copy and paste the script into PowerShell + +Provide the Global Administrator credentials or credentials which has both AzureAD and MicrosoftTeams admin permissions to connect to AzureAD and MicrosoftTeams + +Hit enter to continue + +# Expected Output +Policy types TeamsChannelsPolicy, TeamsMeetingPolicy, TeamsMessagingPolicy with policy name `All teachers` are assigned to **All Teachers** distribution list with rank 1 + +A log file will be generated with exceptions, errors along with script execution time diff --git a/UserAsTeamsOwner/Readme.md b/UserAsTeamsOwner/Readme.md new file mode 100644 index 0000000..1d5b25f --- /dev/null +++ b/UserAsTeamsOwner/Readme.md @@ -0,0 +1,62 @@ +# User As Teams Owner + +# Description + + Script will provide the Teams details where user as the owner of a Team in your organization + +# Prerequisite + + MicrosoftTeams module. Reference-[Microsoft Teams PowerShell Release Notes](https://docs.microsoft.com/en-us/microsoftteams/teams-powershell-release-notes) + +# Procedure + +1. As an Administrator, type PowerShell in the start menu. Right-click on Windows PowerShell, then select Run as Administrator. +Click Yes at the UAC prompt + +2. Type the following within PowerShell and then press enter\ + **`Install-Module MicrosoftTeams`** + +3. Type Y at the prompt. Press enter + +4. If you are prompted for an untrusted repository, then type A (Yes to All) and press Enter. The module will now install + + - Script will prompt you for input user, provide the input to proceed + - To connect to MicrosoftTeams provide the Global Administrator credentials or Teams Administrator credentials + - Script will get the Teams details where user as the owner for the Team in your organization + - Exports details to an output.csv file + +# Example + +User: dmx1@example.com + +|Team Owner| Team Displayname|Teamid| +|-----|----|---| +|dmx1@example.com| HR| 208bfb7a-9d4c-xxxx-8677-18cc7fcxxxxx | +|dmx1@example.com|Accounts|48ddcc0e-xxxx-4131-abf8-36axxxxx86ba| + +# Parameters + +`-UserPrincipalName` + +Specifies the user ID of the user to retrieve. + +Type: String +*** +Position: Named +*** +Default value: None +*** +Accept pipeline input: True +*** +Accept wildcard characters: False + +# Input + +UserPrincipalName + +# Output + The script will export details of user as the owner of MicrosoftTeams in your tenant with following details to an output.csv file +|Team Owner| Team Displayname|Teamid| +|----|---|---| + +A log file will be generated with exceptions, errors along with script execution time diff --git a/UserAsTeamsOwner/UserAsTeamsOwner.ps1 b/UserAsTeamsOwner/UserAsTeamsOwner.ps1 new file mode 100644 index 0000000..eed60fd --- /dev/null +++ b/UserAsTeamsOwner/UserAsTeamsOwner.ps1 @@ -0,0 +1,51 @@ +# This script will provide the Teams details where user is owner for the Team + $logfile = ".\CreateNew-CsTeamsMessagingPolicylog_$(get-date -format `"yyyyMMdd_hhmmsstt`").txt" +$start = [system.datetime]::Now + + If(Get-Module -ListAvailable -Name MicrosoftTeams) + { + Write-Host "MicrosoftTeams Already Installed" + } + else { + try { Install-Module -Name MicrosoftTeams + Write-Host "Installed MicrosoftTeams" + } + catch{ + $_.Exception.Message | out-file -Filepath $logfile -append + } + } + +connect-microsoftteams +$user = Read-host "Please provide User Principle Name" +try{ +$Data = get-team -User "$user" +} +catch{ + $_.Exception.Message | out-file -Filepath $logfile -append + } + +foreach ($teams in $Data) + { + + $groupid = $teams.Groupid + $displayname = $teams.DisplayName + $owner = get-teamuser -GroupId "$groupid" -Role Owner | Where-Object {$_.User -match "$user"} + $owners = [string]::Join("; ",$owner.User) + $groupid + $owners + + if (!($owner -eq $null)) + { + $file = New-Object psobject + $file | add-member -MemberType NoteProperty -Name Teams_Owner $owners + $file | add-member -MemberType NoteProperty -Name Teams_Displayname $displayname + $file | add-member -MemberType NoteProperty -Name Teams_Groupid $groupid + $file | export-csv output.csv -NoTypeInformation -Append + } + } +$end = [system.datetime]::Now +$resultTime = $end - $start +Write-Host "Execution took : $($resultTime.TotalSeconds) seconds." -ForegroundColor Cyan + + +