Share via

Powershell Workflow Scripts for teams

Karthick AP 300 Reputation points
2023-05-28T15:08:41.8266667+00:00

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]
Microsoft Teams | Development
Microsoft Teams | Development

Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Karthick AP 300 Reputation points
    2023-05-29T04:03:22.1733333+00:00

    I figured it out to be a throttling limit set to the command executions. How I found out was, intermittently the command succeeds from that loop. And hence it is something to do with throttling and I don't think Microsoft can help here because the tenant size is way too small.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.