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?