I want to connect to my SQL server to import the SQLPS module. My problem is security to the SQL server. Domain users will be running the script but they don’t have access to the server itself so the New-PSSession cmdlet blows up with ‘access denied’. To test it and make sure the script worked I created an active directory user with domain admin access and do this:
$Password = ConvertTo-SecureString “abcd” -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential (“domainname\aduser”, $Password )
$sql1 = New-PSSession -ComputerName sql1 -Credential $Credentials
Import-PSSession -Session sql1 -Module SQLPS -Prefix sql1 -AllowClobber
Works great, but a million miles from good security and best practice.
What’s the proper way to handle this?