Hi hope someone can help i have a list of users and instances they have access to in a text file like below.

SQL-UAT-DB       domain\testuser
SQL-Prod-DB      domain\Joe.bloggs
SQL-Train-DB     domain\Mary.smith

I want to pass this file into DBtools powershell command "Remove-DbaLogin" https://docs.dbatools.io/Remove-DbaLogin

example of remove-dbalogin is below where you can state the instance and then login i know i can pass 2 separate files to this one for users and one for instances but i want it to pick both up from one file instead.

Remove-DbaLogin -SqlInstance $instances -Login $userlist

How can i pass this one list to this command and have it remove the login based on each line in the file.

1 Answer 1


You can just loop through the lines in the file, and call Remove-DbaLogin on each.

$lines = Get-Content "YourPath";

foreach ($line in $lines) {
    $values = $line.Split(" ", [System.StringSplitOptions]::RemoveEmptyEntries);
    Remove-DbaLogin -SqlInstance $values[0] -Login $values[1];

A more efficient option would be to group up the users by instance, and pass multiple users in one go

  • What if the separator is a TAB character instead of multiple spaces? Commented Aug 6, 2022 at 10:33
  • Then you do $line.Split("``t", that's a single backtick just can't show it in the comments Commented Aug 7, 2022 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.