An Azure service that provides an event-driven serverless compute platform.
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