SQL Service Account creation in AD using PowerShell [closed]
-
29-09-2020 - |
Question
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.
Solution
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
OTHER TIPS
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