I am using a SQL Server job to get some wmiobject details into a table.
This code runs with default installation, but fails when I execute it on a named instance. So far I have seen only one difference in connection, for the named instance, SQL Agent is using with a user name which has "$" as part of the name (i.e. NT Service\SQLAgent$instance
)
Is there anyway I can overcome this? Changing the agent account is not an option as most of the servers run with this account and my code needs to work with all accounts.
$conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=$SqlSvr;Initial Catalog=$Database; Integrated Security=SSPI")
$conn.Open()
Executed as user: NT Service\SQLAgent$instance. A job step received an error at line 21 in a PowerShell script. The corresponding line is ' $conn.Open() '... The error information returned by PowerShell is: 'Exception calling "Open" with "0" argument(s): "Login failed for user '(DOMAIN)(COMPUTER)$'." '. Process Exit Code -1.
I tried with "identity impersonate =true" but it didn't accept the command.
Any ideas?