0 votes

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
}
by (200 points)
edited by
0

Hello,

What exactly do you mean by does not work? Do you face any error messages? If you do, please, post here or send us (support@adaxes.com) screenshots. Also, please, make sure that there is only the latest version of the Microsoft teams PowerShell module installed on the computer where Adaxes service runs.

0

So I have worked out what the issue is - I am bad at scripting.

I watched the file size go from 0 to 1KB a number of times, so it seems like for each user in OU's I specified, it was running the script for every single one.

If I add -append to the command in Adaxes, it generates the list in the spreadsheet 200 times over for everyone in our org.

I've worked around the issue by assigning it the activity scope to be only over a single test user account, which seems to work OK. It's a shame there's not a more elegant way to run it though.

1 Answer

0 votes
by (288k points)

Hello,

Whenever a custom command, business rule or scheduled task is executed, it is executed for an object. As we understand, you have the script in a scheduled task. In cases when all the search criteria are specified in the script itself and do not depend on the Activity Scope, specifying a single object in the scope is the correct approach. Unfortunately, there is no possibility to do that without having a target object at all.

0

oh, ok well that works then, thanks :)

Related questions

0 votes
1 answer

Receive "Index operation failed; the array index evaluated to null. Stack trace: at <ScriptBlock>, <No file>: line 104>" and "Index operation failed; the ... $GroupName, $GroupDN." } } #foreach write-output "" Write-Output "" Stop-Transcript

asked Apr 14, 2022 by jbahou (20 points)
0 votes
1 answer

Hello, Similar to exporting the members of a group to a csv file: https://www.adaxes.com/script-repository/export-group-members-to-csv-file-s184.htm I am looking to ... would like to include the memberof csv report in the email as well. Thanks in advance!

asked Feb 7, 2023 by JonnyBGood (20 points)
0 votes
1 answer

We would like to be able to export logs from the Adaxes service? Is there a way to do this either through the service or reporting?

asked Oct 31, 2022 by scoutcor (120 points)
0 votes
1 answer

Hello I'm trying to run a custom PowerShell script to request a Workspace ONE Access Sync when I change something in our users or groups. Here is the script: $ClientId = "api ... of having to create 6 independent rules with each of them a copy of the script)?

asked Sep 25, 2021 by ygini (240 points)
0 votes
1 answer

I am using this script modified for my testing. Import-Module Adaxes $csvFilePath = "D:\TestFeed\ImportNewUsers.csv" # Path to pick up feed file $userIdColumn = "Employee Number" # TODO: ... initial. I would like to add a 2 for now if the sam isn't unique.

asked Oct 17, 2022 by mightycabal (1.0k points)
3,543 questions
3,234 answers
8,228 comments
547,809 users