About EasyMorph Tutorials & Examples Web-help

Powershell: Connect-MicrosoftTeams

Hi there, I’m trying to do some Phone Number management with EasyMorph. But am running into an error.
I’m currently stuck while trying to run a powershell command.

$Username = "username"
$userPassword = "password"
$Password = ConvertTo-SecureString -String $userPassword -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential $Username,$Password
Connect-MicrosoftTeams -Credential $Credentials
foreach ($number in $input){
$check = ""
$check = Get-CsOnlineUser | where {$_.OnPremLineURI -eq "tel:$number" -or $_.PrivateLine -eq "tel:$number" -or $_.LineURI -eq "tel:$number"} | Sort-Object OnpremLineURI | Select-Object Displayname
$Result += $check
}

Error:
Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=6.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

This command works fine in normal Powershell, but refuses to run through EasyMorph

It appears that there is a conflict of assembly versions between one you expect when command is being run in powershell console and one that is already loaded in EasyMorph AppDomain.

To workaround this, you can create powershell script file (for example, manage-phones.ps1) and run it as powershell command using
cmd /C powershell "path-to-my-script\manage-phones.ps1"

Hi olysak, thank you for the suggested solution.

Is there a way to get the output of that script back into EasyMorph after the job finishes running?

Yes, output should be available if you pick “Capture output and error collections” option in PowerShell action

Hi,

I can’t seem to capture any output from the script that ran.

Any recommendations ?
I’ve tried adding Out-Host / Write-Output / Write-Host / Verbose
Nothing seems to return any output.

Again running the script normally works and returns output as expected.

That’s strange, there should be output, at least for Write-Output I get:

But again if this fails, I can suggest a workaround - save output to temporary file, then read it using Easymorph action…

To learn more about EasyMorph visit easymorph.com.