question

MS-5605 avatar image
0 Votes"
MS-5605 asked NewbieJones-6218 commented

insuficient Memory to countune the execution of the program- PowerShell to export users list

Hi,

We try to export the list of users through a script (get-csonlineusers) that throws the following error.

199985-image.png




The script is intended to export 3 lakh users. I copied a bit from the script where we got an error in the script line 25. It would be great if someone have a solution for this issue.


Get-CsOnlineUser -Filter {(AssignedPlan -eq 'Teams') -and (accountenabled -eq $True) } -ResultSize 300000 | Where-Object {$_.SoftDeletionTimeStamp -eq $null} | Select-Object `
UserPrincipalName, SipAddress, OnPremLineUri, LineUri, City
Thanks in Advance.

Regards,
MS

office-teams-windows-itprowindows-server-powershell
image.png (54.8 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MS-5605

Have you checked if the system was indeed out of memory when the error occurred?

Besides, in order to help narrow down the issue, it's suggested to try slightly modifying the problematic script line by exporting less users and see if the error persists.

0 Votes 0 ·

@YukiSun-MSFT , I tried limiting the user to 1.5 lakh, but I still see the "out of memory" issue. The server has enough memory to handle the script.


201116-image.png






0 Votes 0 ·
image.png (42.5 KiB)

Hi @MS-5605

May I know if you have seen similar errors when running non teams-related powershell commands? According to the error message, personally I'd recommend trying to add the "windows-server-powershell" tag as well so that community users there can help look into this issue as well.

0 Votes 0 ·

The client side filter is not necessary and should be added to the main filter if needed. That will improve the performance slightly (but probably isn't the cause of the memory error).

Out of interest, does the command complete if you remove the client side filter (where-object) and the Select-Object.

300000 accounts does seem like a lot, and I've never had to work with something that large, but RichMatheisen's proposal to partition the search by OU sounds like something worth investigating.

0 Votes 0 ·

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 commented

I think the out-of-memory problem may lie in the returning of that very large number of objects, not to the pipeline in your script, but through the results from the query executed on a remote machine.

Are you running this against your on-prem AD or M365 (i.e. 'the cloud')?
If it's M365, is there more than one tenant? According to the Get-CsOnlineUser help, the cmdlet doesn't have a parameter to narrow its query to a single tenant, but you can add a tenantid to the -Filter parameter to narrow the scope of the search. E.g.:

 Get-CsOnlineUser -Filter "TenantId -eq 'bf19b7db-6960-41e5-a139-2aa373474354'"

Also, check the "Outputs" section of the cmdlet's "help":

The following attributes are temporarily unavailable in the output when using the "-Filter" or when used without the "-Identity" parameter

The "SoftDeletionTimeStamp" property is in that list.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @RichMatheisen-8856 We have only one Tenant with Azure AD, between we have removed the sofDeletoinTimeStamp in the script and re-ran and observed the same error.

0 Votes 0 ·

The SoftDeletionTimestamp would have no effect on your problem. I mentioned it only because your script was needlessly testing a property that isn't in the data.

You may have to partition your search to reduce the number of objects returned by the Get-CSOnlineUser cmdlet. I don't know how your directory is organized, though. One way to do that would be to loop over a list of the OUs that contain users.

1 Vote 1 ·