Creating a credential
This recipe goes through the code needed for creating a SQL Server credential.
Getting ready
In this recipe, we create a credential for a domain account that has access to certain files and folders in our system, QUERYWORKS\filemanager
. The equivalent T-SQL for what we are trying to accomplish is:
CREATE CREDENTIAL [filemanagercred] WITH IDENTITY = N'QUERYWORKS\filemanager', SECRET = N'YourSuperStrongPassword'
You can substitute this with another known Windows account that you have in your environment.
How to do it...
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module and create a new SMO Server object:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "KERRIGAN" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
Add the following script and run it:
$identity = "QUERYWORKS...