Exception calling "GetSteppablePipeline" while using teams module 3.1.1 in Azure function

Willem Klok 1 Reputation point
2022-02-25T09:05:29.043+00:00

I have a fairly simple Azure Powershell function that connects to Teams and requests a user by calling Get-CSOnlineUser. It seems that it randomly succeeds or failes with a "GetSteppablePipeline" error.
This is part of the code:

$securePassword = ConvertTo-SecureString -string $adminPassword -AsPlainText -force
$teamsCredential = New-Object System.Management.Automation.PSCredential ($adminName, $securePassword)
Write-Host "Connecting as $adminName"
Connect-MicrosoftTeams -Credential $teamsCredential

Write-Host "Getting user info for $upn"
$user = Get-CSOnlineUser -Identity "$upn" | Select OnlineVoiceRoutingPolicy, OnPremLineUri, EnterpriseVoiceEnabled, OnlineVoicemailPolicy,DisplayName

And this a log of two sequential calls to the function, with first a success result and in the second call it errors:

2022-02-25T08:51:33.265 [Information] Executing 'Functions.GetOnlineVoiceUser' (Reason='This function was programmatically called via the host APIs.', Id=xxxxx)
2022-02-25T08:51:34.077 [Information] INFORMATION: PowerShell HTTP trigger function processed a request.
2022-02-25T08:51:34.078 [Information] INFORMATION: Loading Teams module
2022-02-25T08:51:58.149 [Information] INFORMATION: Loaded Module 'Microsoft.Teams.ConfigAPI.Cmdlets'
2022-02-25T08:51:58.983 [Information] INFORMATION: Connecting to teams
2022-02-25T08:51:58.989 [Information] INFORMATION: Connecting as xxxxxanonymous user
2022-02-25T08:52:00.348 [Information] OUTPUT:
2022-02-25T08:52:03.768 [Information] INFORMATION: Getting user info for AlexW@Piepel .OnMicrosoft.com
2022-02-25T08:52:05.602 [Information] INFORMATION: returning body = {"upn": "AlexW@Mxxxxx.OnMicrosoft.com", "VoiceRoutingPolicy": "UNRESTRICTED", "LineUri": "", "EnterpriseVoiceEnabled": "True", "VoicemailPolicy": "TranscriptionDisabled", "userDisplayName": "Alex Wilber"}
2022-02-25T08:52:05.602 [Information] OUTPUT: Account Environment Tenant TenantId
2022-02-25T08:52:05.602 [Information] OUTPUT: ------- ----------- ------ --------
2022-02-25T08:52:05.602 [Information] OUTPUT: xxxx@xxxxxx .onmicrosoft.com AzureCloud xxxxxxxxxxxxxxxxxxx
2022-02-25T08:52:05.603 [Information] OUTPUT:
2022-02-25T08:52:05.603 [Information] Executed 'Functions.GetOnlineVoiceUser' (Succeeded, Id=xxxxxxx, Duration=32339ms)
2022-02-25T08:52:18.388 [Information] Executing 'Functions.GetOnlineVoiceUser' (Reason='This function was programmatically called via the host APIs.', Id=xxxxxxx)
2022-02-25T08:52:19.170 [Information] INFORMATION: PowerShell HTTP trigger function processed a request.
2022-02-25T08:52:19.171 [Information] INFORMATION: Loading Teams module
2022-02-25T08:52:45.370 [Information] INFORMATION: Loaded Module 'Microsoft.Teams.ConfigAPI.Cmdlets'
2022-02-25T08:52:45.978 [Information] INFORMATION: Connecting to teams
2022-02-25T08:52:45.978 [Information] INFORMATION: Connecting as xxxxxanonymous user
2022-02-25T08:52:46.278 [Information] OUTPUT:
2022-02-25T08:52:47.259 [Information] INFORMATION: Getting user info for AlexWanonymous user.OnMicrosoft.com
2022-02-25T08:52:47.854 [Error] EXCEPTION: Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object."Exception :Type : System.Management.Automation.ParentContainsErrorRecordExceptionMessage : Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object."HResult : -2146233087CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordExceptionFullyQualifiedErrorId : RuntimeExceptionInvocationInfo :ScriptLineNumber : 67596OffsetInLine : 9HistoryId : -1ScriptName : C:\home\data\ManagedDependencies\2202221459460733933.r\MicrosoftTeams\3.1.1\netcoreapp3.1\exports\ProxyCmdletDefinitions.ps1Line : $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)PositionMessage : At C:\home\data\ManagedDependencies\2202221459460733933.r\MicrosoftTeams\3.1.1\netcoreapp3.1\exports\ProxyCmdletDefinitions.ps1:67596 char:9+ $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvoc …+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot : C:\home\data\ManagedDependencies\2202221459460733933.r\MicrosoftTeams\3.1.1\netcoreapp3.1\exportsPSCommandPath : C:\home\data\ManagedDependencies\2202221459460733933.r\MicrosoftTeams\3.1.1\netcoreapp3.1\exports\ProxyCmdletDefinitions.ps1CommandOrigin : InternalScriptStackTrace : at Get-CsUserPoint<Begin>, C:\home\data\ManagedDependencies\2202221459460733933.r\MicrosoftTeams\3.1.1\netcoreapp3.1\exports\ProxyCmdletDefinitions.ps1: line 67596at Get-CsOnlineUser<Process>, C:\home\data\ManagedDependencies\2202221459460733933.r\MicrosoftTeams\3.1.1\netcoreapp3.1\exports\ProxyCmdletDefinitions.ps1: line 10894at <ScriptBlock>, C:\home\site\wwwroot\GetOnlineVoiceUser\run.ps1: line 32
2022-02-25T08:52:47.905 [Error] Executed 'Functions.GetOnlineVoiceUser' (Failed, Id=4b616058-ac1d-4998-bafe-a005260dc2b2, Duration=29501ms)Result: FailureException: Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object."Stack: at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)at System.Management.Automation.Runspaces.Pipeline.Invoke()at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)at System.Management.Automation.PowerShell.CoreInvokeHelperTInput,TOutputat System.Management.Automation.PowerShell.CoreInvokeTInput,TOutputat System.Management.Automation.PowerShell.InvokeTat System.Management.Automation.PowerShell.InvokeTat Microsoft.Azure.Functions.PowerShellWorker.PowerShell.PowerShellExtensions.InvokeAndClearCommandsT in /home/vsts/work/1/s/src/PowerShell/PowerShellExtensions.cs:line 45at Microsoft.Azure.Functions.PowerShellWorker.PowerShell.PowerShellManager.InvokeNonOrchestrationFunction(DurableController durableController, IDictionary outputBindings) in /home/vsts/work/1/s/src/PowerShell/PowerShellManager.cs:line 294at Microsoft.Azure.Functions.PowerShellWorker.PowerShell.PowerShellManager.InvokeFunction(AzFunctionInfo functionInfo, Hashtable triggerMetadata, TraceContext traceContext, IList`1 inputData, FunctionInvocationPerformanceStopwatch stopwatch) in /home/vsts/work/1/s/src/PowerShell/PowerShellManager.cs:line 229at Microsoft.Azure.Functions.PowerShellWorker.RequestProcessor.InvokeFunction(AzFunctionInfo functionInfo, PowerShellManager psManager, FunctionInvocationPerformanceStopwatch stopwatch, InvocationRequest invocationRequest) in /home/vsts/work/1/s/src/RequestProcessor.cs:line 334at Microsoft.Azure.Functions.PowerShellWorker.RequestProcessor.ProcessInvocationRequestImpl(StreamingMessage request, AzFunctionInfo functionInfo, PowerShellManager psManager, FunctionInvocationPerformanceStopwatch stopwatch) in /home/vsts/work/1/s/src/RequestProcessor.cs:line 307

Any ideas?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,355 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,909 questions
{count} votes

7 answers

Sort by: Most helpful
  1. Willem Klok 1 Reputation point
    2022-02-28T09:43:03.123+00:00

    This is some background info:

    • It is a Azure Powershell Function that uses the Microsoft Teams 3.1.1 module. It is auto installed by configuring requirements.psd1 " 'microsoftteams' = '3.*' "
    • The function is created and deployed with Azure Devops with a PS 'az functionapp create' task and the Azure App Service Deploy task
    • The function app executing Get-CSOnlineUser is triggered by a REST call
    • The script works when running local in PS ISE

    Hope this helps.

    Cheers,
    Willem.

    0 comments No comments

  2. Willem Klok 1 Reputation point
    2022-03-04T12:32:45.81+00:00

    Are you still looking into this issue? Can I help any further?


  3. Afzal Ali 1 Reputation point
    2022-03-05T09:46:07.77+00:00

    We are also facing similar issue. It seems there is an update in the backend services which has broken the remote powershell.
    We have tried going to 3.0.0 and 3.1.1 and even the 3.2.0 preview teams module but all are giving same issue.
    The AssignedPlan is even returning XML for some tenants and JSON for some which is also another issue.

    Microsoft team assistance is required on an urgent note for this reported issue!

    0 comments No comments

  4. Afzal Ali 1 Reputation point
    2022-03-05T09:53:57.797+00:00

    Please note that the error is not appearing from local powershell sessions.

    This only appears when you are triggering the powershell commands from Runspace. We are using using System.Management.Automation.Runspaces and invoking these commands. These were working fine until few weeks ago and started to fail now!

    Steps to reproduce;

    1. Login on remote powershell via a web application by using Connect-MicrosoftTeams -AccessToken xxxx
    2. Try to run Get-CsOnlineUser
    3. Login in parallel again with a different or same user in the same tenant and perform above actions
    4. try performing Set-CsUser for a user by assigning LineUri etc.
    5. the first logged in user will face following error when trying to sync and after that the 2nd user will also face same. Both cannot work at this stage.

    Error Detail:
    Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object."
    System.Management.Automation.MethodInvocationException: Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object." ---> System.Management.Automation.RuntimeException: The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.


  5. Matthew Stone 1 Reputation point
    2022-03-10T18:41:33.037+00:00

    Hi

    I'm also facing a very similar issue. Backgound - I'm running powershell 7.2.1 on a Linux CentOS machine. I'm running Version 4.0 of the Microsoft Teams module which has just been released but have seen similar issues since 3.0.0. When running the commands directly in powershell they work 100% of the time. However when I run through a .NET 6 Application using System.Management.Automation I see the issue.

    Specifically I'm trying to enterprise voice enable a Teams user based on input provided from a web form. I have tried to simplify this as much as I can to rule out any bad code on my part. The code extract from my .net application is as follows

    using (PowerShell ps = PowerShell.Create())
    {
    ps.AddStatement().AddCommand("Start-Transcript").AddParameter("Path", "/var/log/powershellTranscript.log").AddParameter("Append").AddParameter("NoClobber");
    ps.AddStatement().AddCommand("Connect-MicrosoftTeams").AddParameter("Credential", teamsCreds);
    ps.AddStatement().AddCommand("Set-CsPhoneNumberAssignment").AddParameter("Identity", teamsUser.UserPrincipalName).AddParameter("PhoneNumber", teamsUser.DIDNumber).AddParameter("PhoneNumberType", "DirectRouting");
    ps.AddStatement().AddCommand("Grant-CsOnlineVoiceRoutingPolicy").AddParameter("Identity", teamsUser.UserPrincipalName).AddParameter("PolicyName", teamsUser.VoiceRoutingPolicy);
    ps.AddStatement().AddCommand("Grant-CsTenantDialPlan").AddParameter("Identity", teamsUser.UserPrincipalName).AddParameter("PolicyName", teamsUser.TenantDialPlan);
    ps.AddStatement().AddCommand("Grant-CsTeamsEmergencyCallRoutingPolicy").AddParameter("Identity", teamsUser.UserPrincipalName).AddParameter("PolicyName", teamsUser.EmergencyCallRoutingPolicy);
    ps.AddStatement().AddCommand("Disconnect-MicrosoftTeams");
    ps.AddStatement().AddCommand("Stop-Transript");
    ps.Invoke();
    }

    The first time after I start/restart the application it runs successfully. However all subsequent times I run this it fails with the following error.

    $.Exception.Message - Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object."
    $
    .InvocationInfo.ScriptName - /usr/local/share/powershell/Modules/MicrosoftTeams/4.0.0/netcoreapp3.1/exports/ProxyCmdletDefinitions.ps1
    $.InvocationInfo.ScriptLineNumber - 67474
    $
    .InvocationInfo.OffsetInLine - 9

    The error comes specfically when entering the Grant-CsTenantDialPlan and Grant-CsTeamsEmergencyCallRoutingPolicy commands.

    I edited the ProxyCmdletDefinitions.ps1 script specifically the Function Grant-CsUserOrTenantPolicy which is where the error position is located. I added in $myInvocation, so I could check and see what bound parameters where coming across. After this I restarted the web application and run it again. The first time was successful as normal and showed the output of the $myinvocation command in the transcript log file. The second time failed and after checking the logs it looks like the $myInvocation was empty. The two lines from the ProxyCmdletDefinitions.ps1 script, where it fails with the steppable pipeline error are shown below.

    67473 : $scriptCmd = {& $wrappedCmd @PSBoundParameters}
    67474 : $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)

    It seems to fail because the expression after the & is not valid. I believe that is not valid because the $wrapperCmd and $PSBoundParameter values are empty. I'm not sure why they are empty. I can clearly see from the transcript that the parameters are correct when passing to the Grant-CsTenantDialPlan Function but is not being passed to the Grant-CsUserOrTenantPolicy

    Any help to further troubleshoot this would be greatly appreciated.

    Thanks

    0 comments No comments