1414#>
1515
1616# region Configurable Inputs
17- $InputFile = " ExportedManagersDirects.txt"
18- $ChannelName = " Just for Fun"
17+ $CsvInputFile = ' ExportedManagersDirects.txt'
18+ $ChannelName = ' Just for Fun'
1919# endregion
2020
2121# region Data Model
@@ -31,27 +31,27 @@ class Manager {
3131 [bool ] $TeamsEnabled
3232 [bool ] $PassedPrereqs
3333
34- Manager (){
34+ Manager () {
3535 $this.DirectReports = New-Object - TypeName System.Collections.ObjectModel.Collection[" DirectReport" ]
3636 $this.PassedPrereqs = $false
3737 }
3838}
3939# endregion
4040
4141# region Helper Functions
42- Function Get-TimeStamp {
43- return " [{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date )
42+ function Get-TimeStamp {
43+ return ' [{0:MM/dd/yy} {0:HH:mm:ss}]' -f (Get-Date )
4444}
45- Function IsTeamsEnabled ([string ] $upn ) {
45+ function IsTeamsEnabled ([string ] $upn ) {
4646 $user = Get-AzureADUser - ObjectId $upn
4747 foreach ($plan in $user.AssignedPlans ) {
48- if (($plan.ServicePlanId -eq " 57ff2da0-773e-42df-b2af-ffb7a2317929" ) -and ($plan.CapabilityStatus -eq " Enabled" )) {
48+ if (($plan.ServicePlanId -eq ' 57ff2da0-773e-42df-b2af-ffb7a2317929' ) -and ($plan.CapabilityStatus -eq ' Enabled' )) {
4949 return $true
5050 }
5151 }
5252 return $false
5353}
54- Function ProcessData ($Managers ) {
54+ function ProcessData ($Managers ) {
5555 $output = New-Object - type System.Collections.ObjectModel.Collection[" Manager" ]
5656
5757 # Iterate through each manager
@@ -64,7 +64,7 @@ Function ProcessData ($Managers) {
6464
6565 # Iterate over each manager's direct reports
6666 foreach ($directReport in $manager.Directs ) {
67- $directs = $manager.Directs.Split (" , " )
67+ $directs = $manager.Directs.Split (' , ' )
6868 # Iterate over each direct report
6969 foreach ($direct in $directs ) {
7070 if ($null -ne $direct ) {
@@ -88,19 +88,19 @@ Function ProcessData ($Managers) {
8888 return $output
8989}
9090
91- Function CreateChannel ([string ] $GroupId , [string ] $ChannelDisplayName ) {
91+ function CreateChannel ([string ] $GroupId , [string ] $ChannelDisplayName ) {
9292 if (($null -ne $GroupId ) -and ($null -ne $ChannelDisplayName )) {
9393 New-TeamChannel - GroupId $newTeam.GroupId - DisplayName $ChannelDisplayName | Out-Null
9494 Write-Verbose " $ ( Get-Timestamp ) Info: Created '$ ( $ChannelDisplayName ) ' Channel within GroupId($ ( $newTeam.GroupId ) )."
9595 }
9696}
9797
98- Function AddDirectToTeam ([string ] $GroupId , [string ] $UserPrincipalName ) {
98+ function AddDirectToTeam ([string ] $GroupId , [string ] $UserPrincipalName ) {
9999 Add-TeamUser - GroupId $newTeam.GroupId - User $direct.UserPrincipalName
100100 Write-Host " $ ( Get-Timestamp ) Info: Added $ ( $direct.UserPrincipalName ) as a Member of GroupId($ ( $newTeam.GroupId ) )."
101101}
102102
103- Function GetNonEnabledTeamsUsers ([manager ] $Manager ) {
103+ function GetNonEnabledTeamsUsers ([manager ] $Manager ) {
104104 if ($manager.TeamsEnabled -eq $false ) {
105105 Write-Host - ForegroundColor Yellow " $ ( Get-Timestamp ) Warning: Manager:$ ( $Manager.UserPrincipalName ) not enabled for Teams."
106106 }
@@ -111,7 +111,7 @@ Function GetNonEnabledTeamsUsers ([manager] $Manager) {
111111 }
112112}
113113
114- Function CreateTeam ([manager ] $Manager ) {
114+ function CreateTeam ([manager ] $Manager ) {
115115 # Validate both the Manager and Directs are enabled for Teams
116116 if ($Manager.PassedPrereqs ) {
117117 $alias = $Manager.UserPrincipalName.Split (' @' )
@@ -120,7 +120,7 @@ Function CreateTeam ([manager] $Manager) {
120120 if ($Teams.Keys -notcontains $teamName ) {
121121 if ($Teams.Values -notcontains $mailNickName ) {
122122 # Create Team
123- $newTeam = New-Team - DisplayName $teamName - MailNickName $mailNickName - Visibility " Private" - Owner $Manager.UserPrincipalName
123+ $newTeam = New-Team - DisplayName $teamName - MailNickName $mailNickName - Visibility ' Private' - Owner $Manager.UserPrincipalName
124124 Write-Host - ForegroundColor Green " $ ( Get-Timestamp ) Info: Created new team for $ ( $Manager.UserPrincipalName ) with GroupId: ($ ( $newTeam.GroupId ) )."
125125
126126 # Create desired Channel
@@ -132,16 +132,13 @@ Function CreateTeam ([manager] $Manager) {
132132 AddDirectToTeam $newTeam.GroupId $direct.UserPrincipalName
133133 }
134134 }
135+ } else {
136+ Write-Host - ForegroundColor Yellow " $ ( Get-Timestamp ) Warning: Mailnickname $ ( $mailNickName ) already in use. Skipping creating team for $ ( $Manager.UserPrincipalName ) ."
135137 }
136- else {
137- Write-Host - ForegroundColor Yellow " $ ( Get-Timestamp ) Warning: Mailnickname $ ( $mailNickName ) already in use. Skipping creating team for $ ( $Manager.UserPrincipalName ) ."
138- }
139- }
140- else {
138+ } else {
141139 Write-Host - ForegroundColor Yellow " $ ( Get-Timestamp ) Warning: Team already exists for $ ( $Manager.UserPrincipalName ) . No Team created."
142140 }
143- }
144- else {
141+ } else {
145142 Write-Host - ForegroundColor Yellow " $ ( Get-Timestamp ) Warning: Manager:$ ( $Manager.UserPrincipalName ) has the following users not enabled for Teams. No Team created."
146143 GetNonEnabledTeamsUsers $Manager
147144 }
@@ -150,11 +147,11 @@ Function CreateTeam ([manager] $Manager) {
150147
151148# region Script Execution
152149Write-Host - ForegroundColor Green " $ ( Get-Timestamp ) Info: Step 1: Processing input file."
153- $Input = import-csv .\" $ ( $InputFile ) " - Delimiter `t
150+ $CsvInput = Import-Csv .\" $ ( $CsvInputFile ) " - Delimiter `t
154151Write-Host - ForegroundColor Green " $ ( Get-Timestamp ) Info: Step 1: Completed."
155152
156153Write-Host - ForegroundColor Green " $ ( Get-Timestamp ) Info: Step 2: Processing Team Pre-requisites."
157- $Managers = ProcessData $Input
154+ $Managers = ProcessData $CsvInput
158155Write-Host - ForegroundColor Green " $ ( Get-Timestamp ) Info: Step 2: Completed."
159156
160157Write-Host - ForegroundColor Green " $ ( Get-Timestamp ) Info: Step 3: Creating Teams for each Manager, adding Directs and creating custom Channels."
@@ -163,12 +160,12 @@ $AllTeams = Get-Team
163160$Teams = @ {}
164161if ($null -ne $AllTeams ) {
165162 foreach ($team in $AllTeams ) {
166- $Teams.Add ($team.DisplayName , $team.MailNickName )
163+ $Teams.Add ($team.DisplayName , $team.MailNickName )
167164 }
168165}
169166foreach ($Manager in $Managers ) {
170167 CreateTeam $Manager
171168}
172169Write-Host - ForegroundColor Green " $ ( Get-Timestamp ) Info: Step 3: Completed."
173170Write-Host - ForegroundColor Green " $ ( Get-Timestamp ) Info: Exiting.."
174- # endregion
171+ # endregion
0 commit comments