Created
May 1, 2017 18:27
-
-
Save MikeFal/633b5437e40096a08c5c2a1f04294443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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