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.

closed as off-topic by Shawn Melton, Philᵀᴹ, RolandoMySQLDBA, Max Vernon, RLF Dec 9 '15 at 13:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – Shawn Melton, Philᵀᴹ, RolandoMySQLDBA, Max Vernon, RLF
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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

  • 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. :) – Mr.Brownstone 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

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