I'm wondering if it's possible to create a service account remotely from the SQL box using PowerShell, and put the service accounts created in the OU (folder) they belong in AD as part of a unattended SQL install.

Could this be done without having to pre-create the service accounts before SQL installation? I'm able to query the AD from the SQL box by importing the AD module.

  • 1
    It's possible I'm sure, have you read the docs and had an attempt yourself? Where did the attempt fail? – Tom V Dec 8 '15 at 19:15

If you have installed the Active Directory PowerShell components, and the account under which you are running the session has sufficient permission to perform the action, then it is actually pretty simple:

New-ADUser -Name "Jo Bloggs" -GivenName Jo -Surname Bloggs`
-SamAccountName jbloggs -UserPrincipalName jbloggs@corp.contoso.com `
-AccountPassword (Read-Host -AsSecureString "AccountPassword") `
-Path 'OU=Whatever,OU=Blah,DC=corp,DC=contoso,DC=com' `
-PassThru | Enable-ADAccount

The documentation is pretty extensive and can be found here: https://technet.microsoft.com/en-us/library/ee617253.aspx

| improve this answer | |
  • Thanks a million Mr. Brownstone. I don't need this to create an AD user account. I need it to create the service accounts for SQL server components as a prerequisite for installation such as SSIS,SSAS,SQL Agent etc. Thanks a miilion for the response – SQLBen Dec 8 '15 at 10:44
  • No problem - remember to mark your question as answered so that it doesn't remain in the 'abyss of unanswered questions'. You can mark your own answer as the solution I believe. :) – World Wide DBA Dec 8 '15 at 15:19

I think this will work for it:

found on: http://blogs.technet.com/b/heyscriptingguy/archive/2010/01/28/hey-scripting-guy-january-28-2010.aspx

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.