I am exploring the option for Powershell workflow as I am trying a Powershell script for Microsoft teams. I would want to make use of parallel function. However, I notice that, whenever I run the script, the second script block under parallel doesnt work as it throws an error asking me to connect to MicrosoftTeams, however the first script block succeeds without any issue.
Sample script:
workflow getteam1
{
$a = get-team
$count = $a.count
$half = $count / 2
$a1 = $a | Select -first $half
$a2 = $a | Select -Last $half
Parallel
{
foreach ($b in $a1)
{
"First Loop"
Get-TeamUser -GroupId $b.groupid|Select Name
}
foreach ($c in $a2)
{
"Second Loop"
Get-TeamUser -GroupId $c.groupid|Select UserID
}
}
}
Getteam1
Error that I get for the second foreach loop:
Microsoft.PowerShell.Utility\Write-Error : You must call the Connect-MicrosoftTeams cmdlet before calling any other cmdlets.
At getteam1:21 char:21
+
+ CategoryInfo : NotSpecified: (:) [Write-Error], RemoteException
+ FullyQualifiedErrorId : System.Management.Automation.RemoteException,Microsoft.PowerShell.Commands.WriteErrorCommand
+ PSComputerName : [localhost]