Skip to content

Instantly share code, notes, and snippets.

@MikeFal
Created May 1, 2017 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeFal/633b5437e40096a08c5c2a1f04294443 to your computer and use it in GitHub Desktop.
Save MikeFal/633b5437e40096a08c5c2a1f04294443 to your computer and use it in GitHub Desktop.
#This ONLY works with AD users
$cred = Get-Credential
$sql = 'SELECT @@SERVERNAME;SELECT suser_name();'
Invoke-Command -ComputerName PICARD -Credential $cred -ScriptBlock {Invoke-Sqlcmd -ServerInstance PICARD -Query $using:sql}
#This is for SQL users
$cred = Get-Credential
$sql = 'SELECT @@SERVERNAME;SELECT suser_name();'
Invoke-Sqlcmd -ServerInstance PICARD -Query $sql -Username $cred.UserName -Password $cred.GetNetworkCredential().Password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment