get-dsuser

avatar

Hi,
I am trying to get a list of all users so that I can delete them all. The command is only returning 10 users... Any advise would be appreciated! (get-dsusers)
Thanks!

All Comments (3)

avatar

Hello,

By default the page size is set to 10. To retrieve all user accounts, please use the -All switch.

$users = (Get-DSUsers -All).Body.Data


Best regards,

Érica Poirier

avatar

Great thanks Erica.

I am retrieving these users in order to delete them in batch. I see that trying to delete them by name is not working when using remove-dsuser - using get-help is not giving me any details on how to do this. Would you let me know the proper parameters?
Thanks!

avatar

Hello,

It's only possible to delete account using their IDs with the Remove-DSUser cmdlet.

Here is what you can do to delete all users retrieved by the Get-DSUsers -All command. Be careful with this sample script as it won't be possible anymore to connect on the DVLS web UI once all accounts will be deleted. I have added one line to prevent deleting one of the administrator account. You just have to replace the account name MyAdministrator below to kept at least one account.

$users = (Get-DSUsers -All).Body.Data
foreach ($user in $users)
{
if ($user.name -ne "MyAdministrator")
{
Remove-DSUser -CandidUserId $user.id
}
}

Let us know if that helps.

Best regards,

Érica Poirier