Sounds like a headline from the onion.All I want to do is add a new database role to a database and its not working. I understand the error, but I don't know why I'm getting it. It (the code) matches all the various examples I have found on the internet to compare with, so I'm just stuck. Whilst debugging, I can see that all the variables are showing the correct values, I just cant find an issue with it.The error is specifically with this line...$NewRole = New-Object Microsoft.SqlServer.Management.Smo.DatabaseRole $dbname, $RoleName...but it seems ok according to the net and my PoSh books. Would love a bit of help.Import-Module SQLPS -DisableNameChecking$InstanceName="Inst_1"$DBServerName="Serv_1"$TargetServer= "$DBServerName\$InstanceName"$RoleName= "Role1"$dbname="TopTrumps"Function fn-create-role-in-database ([String]$TargetServer, [String]$dbname, [String]$Rolename){$Server = New-Object Microsoft.SqlServer.Management.Smo.Server $TargetServer$NewRole = New-Object Microsoft.SqlServer.Management.Smo.DatabaseRole $dbname, $RoleName$NewRole.Create()}fn-create-role-in-appname-database $TargetServer $dbname $RoleNameThe error I am receiving is...Exception : System.Management.Automation.MethodException: Cannot find an overload for "DatabaseRole" and the argument count: "2". at System.Management.Automation.Adapter.GetBestMethodAndArguments(String methodName, MethodInformation[] methods, PSMethodInvocationConstraints invocationConstraints, Object[] arguments, Object[]& newArguments) at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments) at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)TargetObject : CategoryInfo : InvalidOperation: (:) [New-Object], MethodExceptionFullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommandErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfoScriptStackTrace : at fn-create-role-in-database, C:\Users\username\Documents\Create_DBRole.ps1: line 12 at <ScriptBlock>, C:\Users\username\Documents\Create_DBRole.ps1: line 16PipelineIterationInfo : {}PSMessageDetails : Thank you.D.
↧