SharePoint Server Service Accounts Populating in Active Directory


Self-Note:

Script used to push minimal #service #accounts required for the #SharePoint development server – #PowerShell

$mydom = "dev.com"
$mydomDistinguishedname = (get-addomain).distinguishedname 
$password = "1qaz2wsx@" | ConvertTo-SecureString -AsPlainText -Force 
 
$ouNameSP = "SharePoint Accounts"
$oudnSP = "OU=$ounameSP,$mydomDistinguishedname"
 
$ouNameSQL = "SQL Accounts"
$oudnSQL = "OU=$ounameSQL,$mydomDistinguishedname"
 
#----------------------------> Organizational Unit <---------------------------- 
$spou = Get-ADOrganizationalUnit -Filter * -SearchBase $oudnSP;
if($spou -eq $null){
    New-ADOrganizationalUnit -Name $OUNameSP -Path $mydomDistinguishedname 
    $spou = Get-ADOrganizationalUnit -Filter * -SearchBase $oudnSP;
    Write-Host "$spou Created" -foregroundcolor green 
}
else{
    Write-Host "$spou already exists" -ForegroundColor Yellow
}

$sqlou = Get-ADOrganizationalUnit -Filter * -SearchBase $oudnSQL;
if($sqlou -eq $null){
    New-ADOrganizationalUnit -Name $OUNameSQL -Path $mydomDistinguishedname
    $sqlou = Get-ADOrganizationalUnit -Filter * -SearchBase $oudnSQL;
    Write-Host "$sqlou Created" -foregroundcolor green 
}
else{
    Write-Host "$sqlou already exists" -ForegroundColor Yellow
}
#-----------------------------> SharePoint 2016 <-------------------------------
 
$usersArraySP = @("SP_Farm", "SP_CacheSuperUser", "SP_CacheSuperReader", "SP_Services", "SP_PortalAppPool", "SP_ProfilesAppPool", "SP_SearchService", "SP_SearchContent", "SP_ProfileSync", "SP_ExcelUser", "SP_VisioUser", "SP_PerfPointUser")
 
foreach ($usp in $usersArraySP) {
        New-ADUser -Name $usp -DisplayName $usp -UserPrincipalName "$usp@$mydom" -SamAccountName $usp -AccountPassword $password `
        -ChangePasswordAtLogon  $false -CannotChangePassword $true -PassThru -PasswordNeverExpires $true -Path $spou -Enabled $True
        Write-Host "$usp Created" -foregroundcolor green
 }
 
#----------------------------------> SQL <--------------------------------------
$usersArraySQL = @("SQL_Admin","SQL_Service")
 
foreach ($usql in $usersArraySQL) {
       New-ADUser -Name $usql -DisplayName $usql -UserPrincipalName "$usql@$mydom" -SamAccountName $usql -AccountPassword $password `
        -ChangePasswordAtLogon  $false -CannotChangePassword $true -PassThru -PasswordNeverExpires $true -Path $sqlou -Enabled $True
        Write-Host "$usql Created" -foregroundcolor green
 }

Output: