0

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.

Charlieface
17.6k22 silver badges45 bronze badges
asked Jul 27, 2022 at 13:01

1 Answer 1

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) {
 $line;
 $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

answered Jul 27, 2022 at 14:56
2
  • 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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.