Get mobile devices for cloud users

This is part of a larger script and I want to focus my question on a particular aspect.

What I run this command, it returns the first 10 devices and then hangs. I can do a ctrl-c to break out.

Any ideas why? Any way around it. I wan to avoid using the get-mailbox and a for loop to Get-MobileDevice as that would take forever.
Get-MobileDevice | Select-Object -First 10 | ft

Are you sure it hangs? Give it a little more time. Try it.

The hang can be in next immediate or somewhere down the line in your script. its better to debug using an editor (VSCode or PowerShell ISE) to confirm the point where it hangs.

No. When I have the command as “Select-Object -First 10” and the scripts returns 10 items it means the script is complete and should return to the prompt but it just sits there.

Its just a single line of powershell code, so there should be no error in the line itself. Try it out. you will see what I mean.

Of course I tried before I answered. The command line delivers the 10 rows and then takes a few moments to come back and show the prompt. It takes some seconds but it does not hang. The time Powershell needs may depend on the size of the environment.