Add Windows User to local SQL Server with PowerShell

后端 未结 4 1890
清歌不尽
清歌不尽 2021-01-24 18:08

I would like to add an existing local user to the SQL Server as a sysadmin, with PowerShell. fter some research I have the following script so far:

$Username = \         


        
4条回答
  •  走了就别回头了
    2021-01-24 18:27

    Found something simpler

    Add-SqlLogin -ServerInstance -LoginName -LoginType -DefaultDatabase tempdb -Enable -GrantConnectSql -LoginPSCredential $Credential
    ((New-Object ('Microsoft.SqlServer.Management.Smo.Server') "").Roles | where {$_.Name -eq 'sysadmin'}).AddMember("")

提交回复
热议问题