Note that there are some explanatory texts on larger screens.

plurals
  1. POInvoke-SQLCmd with Different Credential
    primarykey
    data
    text
    <p>Background: I am running a script locally that has to be run as SYSTEM, lets not get into why that is. :) The script attempts to check the health of my MSSQL cluster with a simple query. The problem I am running into however is that the local SYSTEM account doesn't have access to the remote database. At this point I've tried a number of things, which I'll get into in a moment, but I'm honestly up for any solution that makes sense. If it means creating a local account in the database that can answer my simple query that's fine too.</p> <p>There is what I have so far:</p> <pre><code>$Server = 'myserver.domain.tld' $Database = 'myDatabase' $Query = 'SELECT DB_NAME() AS DataBaseName' $Username = 'myDomain\myUsername' $Password = 'myPasswordWithPlainText' Invoke-SQLCmd -ServerInstance $Server -Database $Database -ConnectionTimeout 300 -QueryTimeout 600 -Query $Query -Username $Username -Password $Password </code></pre> <p>The result: <code>Invoke-Sqlcmd : Login failed for user 'myDomain\myUsername'</code></p> <p>Maybe Invoke-SQL doesn't take Windows authentication I thought, but it doesn't use -Credential. So then I tried to use Invoke-Command as a wrapper.</p> <pre><code>$Server = 'myserver.domain.tld' $Database = 'myDatabase' $Query = 'SELECT DB_NAME() AS DataBaseName' $Username = 'myDomain\myUsername' $Password = 'myPasswordWithPlainText' $secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ($Username, $secpasswd) Invoke-Command -script {Invoke-SQLCmd -ServerInstance $Server -Database $Database -ConnectionTimeout 300 -QueryTimeout 600 -Query $Query} -Credential $Credential </code></pre> <p>Which got me: <code>Invoke-Command : Parameter set cannot be resolved using the specified named parameters.</code></p> <p>So.. I'm stuck. Any thoughts? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload