I have a script that connects to Microsoft Teams and then adds a list of users to a policy. It works perfectly fine, but I keep getting a message saying that it imported a module. This message appears when first connecting to Teams and when running it in a parallel loop. The final script will run over thousands of users so it will need to be parallel to save time. Here is a test script that I used to try to suppress the message:
echo "getting credentials"
# redacted. Just gets sets $AzCredential and $Email
echo "connecting to teams"
Connect-MicrosoftTeams -Credential $AzCredential -Verbose:$false | Out-Null 3>$null
echo "done connecting to teams"
echo "setting permission policy"
Grant-CsTeamsAppPermissionPolicy -Identity $Email -PolicyName $null
echo "setting setup policy"
Grant-CsTeamsAppSetupPolicy -Identity $Email -PolicyName $null
$List = @('a','b')
echo "STARTING STANDARD LIST"
$List | foreach-object {
echo "doing standard list: $psitem"
Grant-CsTeamsAppSetupPolicy -Identity $Email -PolicyName $null
}
echo "STARTING PARALLEL LIST"
$List | foreach-object -parallel {
echo "doing parallel list: $psitem"
$Test = Grant-CsTeamsAppSetupPolicy -Identity $using:Email -PolicyName $null -Verbose:$false | Out-Null 3>$null
}
echo "DONE"
And below is the output. It only prints the message when first connecting to Teams and inside the parallel loop. Given the nature of parallel loops it makes sense that it attempts to re-import the module but I am trying to figure out how to hide the message.
getting credentials
connecting to teams
Loaded Module 'Microsoft.Teams.ConfigAPI.Cmdlets'
done connecting to teams
setting permission policy
setting setup policy
STARTING STANDARD LIST
doing standard list: a
doing standard list: b
STARTING PARALLEL LIST
doing parallel list: a
doing parallel list: b
Loaded Module 'Microsoft.Teams.ConfigAPI.Cmdlets'
Loaded Module 'Microsoft.Teams.ConfigAPI.Cmdlets'
DONE
As a side note, I did test running 200 users on both a parallel and non-parallel loop, and it was significantly faster to use parallel, so I would like to continue using it.
Does anybody know of a way to completely suppress the loading module message?