-
Notifications
You must be signed in to change notification settings - Fork 19
/
random users add.ps1
29 lines (24 loc) · 1.87 KB
/
random users add.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$SqlInstance = 'localhost'
$databases = (Get-DbaDatabase -SqlInstance $SqlInstance -ExcludeSystem).Name
$logins = 'benji', 'bweissman','akamman', 'alevy', 'beardapp1', 'beardapp2', 'beardapp3', 'beardapp4', 'beardapp5', 'beardapp6', 'beardapp7', 'beardapp8', 'clemaire', 'csilva', 'fatherjack', 'gsartori', 'jamrtin', 'Reporting1', 'Reporting2', 'Reporting3', 'Reporting4', 'smelton', 'SockFactoryApp_User', 'soneill', 'sqladmin', 'Support1', 'Support2', 'Support3', 'Support4', 'Support5', 'Support6', 'tboggiano', 'thebeard', 'wdurkin','Argenis_Fernandez','MrsFatherJack',,'Cathrine_Wilhelmsen','Rie_Irish','Monica_Rathbun','Benji_BenWeissman','Joey_Dantoni', 'John_Morehouse', 'Bob_Facts_Pusatari','Containers_Nocentino','Andrew_Pruski','Matt_Gordon','Thomas_Grohser','Dirk_Hondong','Father_Johan_Brattas','Drew_FurggerwellyIgiveuptryingtospellit'
$pwd = 'Password0!'
$secpwd = ConvertTo-SecureString $pwd -AsPlainText -Force
foreach ($login in $logins) {
New-DbaLogin -SqlInstance $SqlInstance -Login $login -SecurePassword $secpwd -Force
}
$roles = 'db_accessadmin', 'db_backupoperator', 'db_datareader', 'db_datawriter', 'db_ddladmin', 'db_denydatareader', 'db_denydatawriter', 'db_owner', 'db_securityadmin'
foreach ($login in $logins) {
$DbNumber = Get-Random -Minimum 2 -Maximum $Databases.Count
$Dbs = Get-Random $databases -Count $DbNumber
foreach ($db in $dbs) {
$rolenumber = Get-Random -Minimum 1 -Maximum $roles.Count
$rolestoadd = Get-Random $roles -Count $rolenumber
New-DbaDbUser -SqlInstance $SqlInstance -Database $db -Login $login
Add-DbaDbRoleMember -SqlInstance $SqlInstance -Database $db -Role $rolestoadd -User $login -Confirm:$false
}
}
#clear up
foreach($db in $databases){
# Remove-DbaDbUser -SqlInstance $SqlInstance -database $db -User $logins
}
# Remove-DbaLogin -SqlInstance $SqlInstance -Login $logins -Confirm:$false