So I need to export a list of all user's Line URI's to a CSV file.
Running Adaxes 2021 Version 3.14.18804.0 (64 bit) and Teams Powershell 4.1.0
It works OK doing this manually through Powershell as follows:
get-csonlineuser | where-object {($_.UsageLocation -eq "NZ") -and (($_.Company -eq "ourcompanyname") -or ($_.Company -eq "ourothercompany")) -and (($_.City -eq "Auckland") -or ($_.City -eq "Wellington")) -and ($_.AccountEnabled -eq "True") -and ($_.Title -ne "contractor")} | select userprincipalname,Company,City,LineURI | Sort-Object -Property Company,City,LineURI,userprincipalname
| export-csv c:\temp\teamsusers.csv
However when I put it into Adaxes as follows it does not work. Can someone please advise what I need to do to make this work?
# Get saved credentials
$username = $Context.RunAs.UserName
$password = $Context.RunAs.Password | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PsCredential($username, $password)
try
{
#Connect to Teams and export a list of staff to CSV file
Connect-MicrosoftTeams -Credential $credential
get-csonlineuser | where-object {($_.UsageLocation -eq "NZ") -and (($_.Company -eq "ourcompany") -or ($_.Company -eq "ourothercompany")) -and (($_.City -eq "Auckland") -or ($_.City -eq "Wellington")) -and ($_.AccountEnabled -eq "True") -and ($_.Title -ne "contractor")} | select userprincipalname,Company,City,LineURI | Sort-Object -Property Company,City,LineURI,userprincipalname | export-csv c:\temp\teamsusers.csv
}
catch
{
return # The user doesn't have a Microsoft 365 account
}
finally
{
# Close the connection and release resources
Disconnect-MicrosoftTeams
}