Windows Authentication

Mar 6, 2014 at 2:15 PM

Firstly, great piece of code. I have used it and like it a lot. However I do have a slight problem.

In my company, we get 2 domain accounts within active directory. One is used for access to servers and the other is used for workstations. etc but we have our workstation account in the sysadmin group across our sql servers.

How would I go about running the script under my account used to connect to servers to pull server related info and then somehow tell the sql part to used my other account?

Mar 6, 2014 at 2:34 PM
Hey Karl,
Supplying different credentials for Windows vs. SQL as parameters is on my long term to-do list but in the meantime the way to accomplish this is twofold: Use runas and your domain account that has access to servers to gather Windows information and a SQL login for gathering SQL Server data.

For the runas piece you're going to launch a PowerShell console with the /netonly option so that the console uses your workstation account profile but a different set of credentials when accessing network resources, e.g.:
runas /netonly /user:DOMAIN\username "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
I know this isn't the most ideal scenario - especially if you don't have mixed authentication enabled on your instances.

Thanks for using SQL Power Doc!