Clean up vars as soon as possible

Signed-off-by: Luke Tainton <luke@tainton.uk>
This commit is contained in:
2020-03-24 19:53:17 +00:00
parent 78311a0fcb
commit c42dd1083a

View File

@@ -40,7 +40,7 @@ Function Import-TeamsUsers {
Clear-Host Clear-Host
Write-Host -ForegroundColor Green "Getting your teams - please wait" Write-Host -ForegroundColor Green "Getting your teams - please wait"
$EligibleTeams = @() $EligibleTeams = @()
Get-Team -User $Email | ForEach-Object { Get-Team -User $Email -Verbose:$false | ForEach-Object {
$CTeamId = $_.GroupId $CTeamId = $_.GroupId
$CTeamName = $_.DisplayName $CTeamName = $_.DisplayName
If (Get-TeamUser -GroupId $CTeamId | Select-Object -Property User,Role | Where-Object {$_.User -eq $Email} | Where-Object {$_.Role -eq "owner"}) { If (Get-TeamUser -GroupId $CTeamId | Select-Object -Property User,Role | Where-Object {$_.User -eq $Email} | Where-Object {$_.Role -eq "owner"}) {
@@ -51,7 +51,7 @@ Function Import-TeamsUsers {
} }
Clear-Host Clear-Host
Write-Host "Teams that you own:" Write-Host "Teams that you own:"
$EligibleTeams | ForEach {[PSCustomObject]$_} | Format-Table 'GroupId', 'DisplayName' -AutoSize $EligibleTeams | ForEach-Object {[PSCustomObject]$_} | Format-Table 'GroupId', 'DisplayName' -AutoSize
$GroupId = Read-Host -Prompt "GroupId of the desired group" $GroupId = Read-Host -Prompt "GroupId of the desired group"
##### ENROL USERS ##### ##### ENROL USERS #####
@@ -69,16 +69,17 @@ Function Import-TeamsUsers {
} Catch [Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException] { } Catch [Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException] {
Write-Host -ForegroundColor Red "Error adding user $User with role $Role" Write-Host -ForegroundColor Red "Error adding user $User with role $Role"
} }
Clear-Variable -Name User
Clear-Variable -Name Role
} }
Write-Host -ForegroundColor Green "$global:UsersAdded users added successfully."
} Else { } Else {
Write-Host -ForegroundColor Red "Aborting." Write-Host -ForegroundColor Red "Aborting."
Exit
} }
} }
End { End {
Write-Host -ForegroundColor Green "$global:UsersAdded users added successfully." @('UserCount', 'UsersAdded', 'Consent', 'Users', 'GroupId') | ForEach-Object {Clear-Variable -Name $_}
Disconnect-MicrosoftTeams Disconnect-MicrosoftTeams
} }
} }