Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Add domain user as sysadmin in SQL Server 2012 using PowerShell

$
0
0

Hi,

I am using the following PowerShell script to add a domain user to SQL Server 2012 as sysadmin, but I encounter an exception.

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null; $svr = New-Object ('Microsoft.SqlServer.Management.Smo.Server') "SQL2012"; $svrole = $svr.Roles | where {$_.Name -eq 'sysadmin'}; $svrole.AddMember("domainname\username");

The exception it throws is as follows:

Exception calling "AddMember" with "1" argument(s): "Add member failed for ServerRole 'sysadmin'. "
At line:1 char:237
+ [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null; $svr = New-Object ('Microsof
t.SqlServer.Management.SMO.Server') "SQL2012"; $svrole = $svr.Roles | where {$_.Name -eq 'sysadmin'}; $svrole.AddMember
 <<<< ("domainname\username");
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Please could someone possibly help?


Admin QuikView Solution for CRM 2013


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>