Azure / azure-functions-powershell-worker

PowerShell language worker for Azure Functions.
MIT License
202 stars 52 forks source link

Failure to connect using the MicrosoftTeams 2.0.0 PowerShell module in function #611

Open mariussm opened 3 years ago

mariussm commented 3 years ago

Trying to use the MicrosoftTeams PowerShell module version 2.0.0 as a managed dependency causes Connect-MicrosoftTeams to error out with the following error message, with chinese characters:

Exception calling "GetSteppablePipeline" with "1" argument(s): "Exception calling "GetRemoteNewCsOnlineSession" with "1" argument(s): "Connecting to remote server api.interfaces.records.teams.microsoft.com failed with the following error message : 錐ۈ껰৲ For more information, see the about_Remote_Troubleshooting Help topic.""

This happens only when loading the module without the -UseWindowsPowerShell parameter for Import-Module:

PowerShell example

Import-Module MicrosoftTeams
$Credential = [pscredential]::new($Username, $Password)
$ConnectionResult = Connect-MicrosoftTeams -Credential $Credential

requirements.psd1

@{
    # 'Az' = '4.*'
    "CosmosDB" = "4.4.3"
    "MicrosoftTeams" = "2.0.0"
}

When using the -UseWindowsPowerShell parameter, I experience my function as unstable, often failing.

I have also tried Save-Module and having the module as files, loading it from there rather than managed dependency. Same issue.

This is a durable PowerShell 7 function.

Edit: Forgot to add the fact that everything works perfectly when running the function runtime locally.

erwanolivo commented 3 years ago

I get a similar issue. I am trying to use MicrosoftTeams cmdlet in an Azure Function v3 (http trigger), with PowerShell v7.

I am able to login with Connect-MicrosoftTeams -Credential $cred.

When trying to use some old skypeonlineconnector cmdlets (for example, Get-CsOnlineUser), I do have the same exception :

Exception calling "GetSteppablePipeline" with "1" argument(s): "Object reference not set to an instance of an object."

It does work for "classical" cmdlet, for example Get-Team...

Works in a local environment. I also tried by installing the MicrosoftTeams modules directly in the Modules folder.

PowerShell example


Connect-MicrosoftTeams -Credential $cred

#Raise an exception
try {
    $user = Get-CsOnlineUser -Identity "herve.losse@###.onmicrosoft.com" -ErrorAction Stop
}
catch {
    Write-Host $_.Exception.Message
}

#Works
try {
    $teams = Get-Team -ErrorAction Stop
}
catch {
    Write-Host $_.Exception.Message
}

requirements.psd1


@{
    'MicrosoftTeams' = '2.0.0'
}
lafe commented 3 years ago

I have the same issue with the current stable 2.0 version. I experimented with the unstable 2.1 version and it seems to work. My requirements.psd1:

@{
    'Az' = '5.*'
    'MicrosoftTeams' = '2.1.0-preview' 
}

Not sure if the Az module is necessary for Teams only, but I have some other commands in the script that requires it and maybe this has also a side effect on the MicrosoftTeams module.

erwanolivo commented 3 years ago

I just tried with the 2.1.0-preview MicrosoftTeams module, it seems to work also.

Not sure if the Az module is necessary for Teams only, but I have some other commands in the script that requires it and maybe this has also a side effect on the MicrosoftTeams module.

I don't have the 'Az' module installed, so only the package itself seems to be enough.

I suppose we have now to wait for a stable package !

Francisco-Gamino commented 3 years ago

Hello @tameemansari and @brandber -- Do you know if the issues above are fixed in the latest version of the MicrosoftTeams module (https://www.powershellgallery.com/packages/MicrosoftTeams/2.4.0-preview).