This recipe goes through the code needed for creating a SQL Server credential.
In this recipe, we will create a credential for a domain account that has access to certain files and folders in our system, QUERYWORKS\filemanager
. Here's the equivalent T-SQL of what we are trying to accomplish:
CREATE CREDENTIAL [filemanagercred] WITH IDENTITY = N'QUERYWORKS\filemanager', SECRET = N'YourSuperStrongPassword'
You can substitute this with another known Windows account you have in your environment.
These are the steps to create a credential:
Open PowerShell ISE as an administrator.
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 = "localhost" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
Add the following script and run:
$identity = "QUERYWORKS\filemanager" $credentialName...