Forked from jibinpb/create_gmsa_windows_servers.ps1
Last active
September 30, 2019 23:21
-
-
Save lavahot/47c70cee5fc63db17406dc7d2da0b90b to your computer and use it in GitHub Desktop.
Create gMSA for Windows Servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-module activedirectory | |
$gMSAName = 'gMSA_Account_Name' ## Replace this value with new gMSA Name | |
$serverList = 'Server001','Server002','Server003','Server004','Server005' ## Replace with Server Names | |
$adOU = 'ou=Managed Service Accounts,OU=Service Accounts,DC=your_company,DC=com' ## Replace with actual AD OU | |
## Checking whether organizational unit exists, if not create it. | |
$ous = dsquery ou "$adOU" | |
if ($ous.count -eq 0) { | |
dsadd ou "$adOU" | |
} | |
## Create a Group Managed Service Account | |
$NameOfServersAccountIsToBeUsedOn = $serverList.ForEach{ return (Get-ADComputer $_) } | |
Write-Output $NameOfServersAccountIsToBeUsedOn | |
##Creating the gMSA | |
$serviceAcct = @( | |
Name = $gMSAName | |
Path = "$adOU" | |
DNSHostName = "$gMSAName.your_company.com" | |
PrincipalsAllowedToRetrieveManagedPassword = $NameOfServersAccountIsToBeUsedOn | |
TrustedForDelegation = $true | |
) | |
New-ADServiceAccount @serviceAcct |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment