I’ve a powershell script that queries from the native server for a listing of servers after which iterates by that checklist of servers, connects to them, queries some information, after which connects and inserts that information domestically.
The powershell works completely tremendous if I run it in Powershell ISE, however after I put it right into a powershell step in a SQL Agent job it fails. I’ve the job utilizing a proxy sql agent account that I arrange that makes use of a home windows account, let’s name it domainPowershellAgent. I’ve granted the account PowershellAgent adequate permissions on the server so far as I can inform, however I nonetheless get the error.
The complete error is:
Login failed. The login is from an untrusted area and can’t be
used with Home windows authentication.
What can I do to get this working?
Instance of a connection:
$sqlConnection = new-object System.Information.SqlClient.SqlConnection $sqlConnection.ConnectionString = "Server='$server'; Database=DBADatabase;Trusted_Connection=True;Join Timeout=5; MultiSubnetFailover=Sure" $sqlConnection.Open() $sqlCommand = new-object System.Information.SqlClient.SqlCommand $sqlCommand.Connection = $sqlConnection $sqlCommand.CommandText = $Question $sqlCommand.CommandType = [System.Data.CommandType]::Textual content $sqlCommand.CommandTimeout = 60 $sqlCommand.Parameters.Add("@id", [System.Data.SqlDbType]::Int).worth = $id $DataReader = $sqlCommand.ExecuteReader() $Datatable.Load($DataReader)