question

WillemKlok-1018 avatar image
0 Votes"
WillemKlok-1018 asked Sayali-MSFT-0291 commented

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

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 xxxxx@xxxxxxxx
2022-02-25T08:52:00.348 [Information] OUTPUT:
2022-02-25T08:52:03.768 [Information] INFORMATION: Getting user info for AlexW@xxxxx.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 xxxxx@xxxxxxxx
2022-02-25T08:52:46.278 [Information] OUTPUT:
2022-02-25T08:52:47.259 [Information] INFORMATION: Getting user info for AlexW@xxxxxxxx.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.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, IList`1 output, PSInvocationSettings settings)at System.Management.Automation.PowerShell.Invoke[T]()at Microsoft.Azure.Functions.PowerShellWorker.PowerShell.PowerShellExtensions.InvokeAndClearCommands[T](PowerShell pwsh) 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-functionsoffice-teams-app-dev
· 11
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@WillemKlok-1018 - We have raised bug for the issue and concerned team is looking into it. We will inform you once we get any update.

1 Vote 1 ·

@WillemKlok-1018 - We are looking into this I will get back to you soon.

0 Votes 0 ·

@WillemKlok-1018 - We are unable to reproduce the error. Could you please share the repro steps to reproduce the issue ?

0 Votes 0 ·

Same issue here:
works fine with teams module 2.6 but after 3.0> it stops for the 2nd user with
"The expression after '&' in a pipeline element produced an object that was not valid.

for command Grant-CsTenantDialPlan -Identity $mail -PolicyName $CsTenantDialPlan
on Server 2012r2

0 Votes 0 ·

@WillemKlok-1018 -Could you please give us the entire script including how can you importing the teams module in the azure function? hide any credentials but we need entire script for testing purpose.

0 Votes 0 ·

188309-runps1.txt



The Teams Module is installed with requirements.psd1:

This file enables modules to be automatically managed by the Functions service.

See https://aka.ms/functionsmanageddependency for additional information.

@{

 'microsoftteams' = '3.*'

}

0 Votes 0 ·
runps1.txt (2.2 KiB)

@WillemKlok-1018 -Thank you for details.

0 Votes 0 ·
Show more comments

@WillemKlok-1018 -Could you please check it once as MatthewStone-0754 mention above?

0 Votes 0 ·
Show more comments
WillemKlok-1018 avatar image
0 Votes"
WillemKlok-1018 answered

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.




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WillemKlok-1018 avatar image
0 Votes"
WillemKlok-1018 answered Sayali-MSFT-0291 edited

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

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@WillemKlok-1018-We are discussing with engineering team, We will inform you once we get any update.

0 Votes 0 ·

Is there any progress? In the meantime we migrated to Teams module 4.0.0 and the error still exists.

0 Votes 0 ·

@WillemKlok-1018 -There is a new release planned by end of this week. It has a few fixes which can resolve this issue. We can wait for that release to go through.
We will inform you once it is fixed.

1 Vote 1 ·
syedafzalali2 avatar image
0 Votes"
syedafzalali2 answered

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!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

syedafzalali2 avatar image
0 Votes"
syedafzalali2 answered syedafzalali2 commented

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.

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@syedafzalali2 :-Thank you for more information. We are tried to repro the scenario with our internal team and let you know once we get any update.

1 Vote 1 ·

@Sayali-MSFT-0291 , Could you please reach out to me offline so that we can discuss this issue?

0 Votes 0 ·
Sayali-MSFT-0291 avatar image Sayali-MSFT-0291 MughundhanRaveendran-MSFT ·

@ MughundhanRaveendran-MSFT- Sure.

0 Votes 0 ·

@Sayali-MSFT-0291 @MughundhanRaveendran-MSFT

Is there any update on this issue please?

0 Votes 0 ·

@syedafzalali2 - Sorry for the delay. Engineering team working on this issue. Currently we don’t have ETA or Update on this thread.
We will update this thread once the bug is fixed.

1 Vote 1 ·

Appreciate your prompt response and confirming there is work in progress on this.
Meanwhile, Is there anyway, we may do some workarounds to get away with it? The issue appears only using System.Management.Automation.PowerShell from C#. Also, this to me looks like a server session issue as when we create two separate IIS Applications, the second site also continue to work in parallel only for one user.

The same issue is not happening on Windows Powershell or ISE consoles hence this is something to be linked with IIS pool and sessions mingling up etc.

0 Votes 0 ·
MatthewStone-0754 avatar image
0 Votes"
MatthewStone-0754 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PIERRELEQUERE-6560 avatar image
0 Votes"
PIERRELEQUERE-6560 answered



Hello , Error occurred during powershell request Powershell error(s): Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid.

i have the same problem with a Teams script. im developing an application for teams , i use module teams 4.0.0.

This application permit to create "Ressource account" and "Teams Users" ( Put Voice etc...)

Each request has been sent in C# runspace. Runspace are installed on Windows server on IIS.

Sometimes , i have GetSteppablePipeline Error , my only solution is that reboot IIS or runspace.

I don't have this problem in ISE


Regards

Pierre

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.