PowerShell
Edit|Remove
# Powershell script to create the User accounts for System Center Operations Manager 2016 
# User: Roel Knippen  
# Date: 29-11-2016 
# Note: System Center Operations Manager needs the following Service Accounts 
# - Opsmgr Action Account 
# - Opsmgr Data Access 
# - Opsmgr SQL Data Warehouse Write account  
# - Opsmgr SQL Data Warehouse Read account  
# I also create a group fore Opsmgr Administrators 
# Change the <XXX> Values to your own Values  
 
# Declare variable. 
 
$Group = "<XXX>" 
$GroupDescription = "<XXX>" 
$GroupPath = "OU=<XXX>,OU=<XXX>,OU=<XXX>,DC=<XXX>,DC=<XXX>" 
$Users = "<XXX>""<XXX>""<XXX>""<XXX>" 
$UserPath = "OU=<XXX>,OU=<XXX>,OU=<XXX>,DC=<XXX>,DC=<XXX>" 
$Password = (ConvertTo-SecureString -String "<XXX>" -AsPlaintext -Force) 
$Domain = "<XXX>" 
 
# Check if module Active Directory is loaded if not loaded then load the module. 
 
Write-Host "Checking to see if the Active Directory Powershell module is installed" 
if ((get-module -Name ActiveDirectory -ErrorAction SilentlyContinue | foreach {$_.Name}) -ne "ActiveDirectory") 
{ 
    write-Host "Active Directory Management PowerShell module is not imported. Importing write now.... 
." 
    Import-Module ActiveDirectory 
} 
else 
{ 
    write-Host "Active Directory Management Powershell moduel is imported"    
} 
 
# Creating Groups and Accounts 
write-Host "Check if Active Directory Group exists" 
 
if (@(Get-ADGroup $Group -ErrorAction SilentlyContinue)) 
{ 
    Write-Host "Group" $Group "Already Exists" 
} 
Else 
{ 
    Write-Host "Create group"  
    New-ADGroup $Group -Groupscope Global -GroupCategory Security -Path $GroupPath -Description $GroupDescription 
} 
  
Foreach ($User in $Users) 
{ 
    if (@(Get-ADUser -Identity $User -ErrorAction SilentlyContinue -WarningAction SilentlyContinue)) 
    { 
        Write-Host "User account" $User "Already exists" 
    } 
    else 
    { 
        Write-Host "Create account" $User 
        New-AdUser -Name $User -GivenName $User -Surname $user -SamAccountName $User -UserPrincipalName "$User@$Domain" -AccountPassword $Password -Path $UserPath -PassThru | Enable-ADAccount 
        if ($User -eq "<XXX>"#The account you want to use for Opsmgr Action Account 
        { 
            Add-ADGroupMember $Group -Members $User  
        } 
        if ($User -eq "<XXX>"#The account you want to use for Opsmgr Data Access 
        { 
            Add-ADGroupMember $Group -Members $User  
        } 
    } 
}  
 
 
 Powershell script to create the User accounts for System Center Operations Manager 2016

 

# Powershell script to create the User accounts for System Center Operations Manager 2016
# User: Roel Knippen
# Date: 29-11-2016
# Note: System Center Operations Manager needs the following Service Accounts
# - Opsmgr Action Account
# - Opsmgr Data Access
# - Opsmgr SQL Data Warehouse Write account
# - Opsmgr SQL Data Warehouse Read account
# I also create a group fore Opsmgr Administrators
# Change the <XXX> Values to your own Values
# Declare variable.
$Group = "<XXX>"
$GroupDescription = "<XXX>"
$GroupPath = "OU=<XXX>,OU=<XXX>,OU=<XXX>,DC=<XXX>,DC=<XXX>"
$Users = "<XXX>", "<XXX>", "<XXX>", "<XXX>"
$UserPath = "OU=Service,OU=Users,OU=Opsmgr,DC=ms-opsmgr,DC=eu"
$Password = (ConvertTo-SecureString -String "<XXX>" -AsPlaintext -Force)
$Domain = "<XXX>"
# Check if module Active Directory is loaded if not loaded then load the module.
Write-Host "Checking to see if the Active Directory Powershell module is installed"
if ((get-module -Name ActiveDirectory -ErrorAction SilentlyContinue | foreach {$_.Name}) -ne "ActiveDirectory")
{
    write-Host "Active Directory Management Powershell is not imported. Importing write now....."
    Import-Module ActiveDirectory
}
else
{
    write-Host "Active Directory Management Powershell is imported"  
}
# Creating Groups and Accounts
write-Host "Check if Active Directory Group exists"
if (@(Get-ADGroup $Group -ErrorAction SilentlyContinue))
{
    Write-Host "Group" $Group "Already Exists"
}
Else
{
    Write-Host "Create group"
    New-ADGroup $Group -Groupscope Global -GroupCategory Security -Path $GroupPath -Description $GroupDescription
}
 
Foreach ($User in $Users)
{
    if (@(Get-ADUser -Identity $User -ErrorAction SilentlyContinue -WarningAction SilentlyContinue))
    {
        Write-Host "User account" $User "Already exists"
    }
    else
    {
        Write-Host "Create account" $User
        New-AdUser -Name $User -GivenName $User -Surname $user -SamAccountName $User -UserPrincipalName "$User@$Domain" -AccountPassword $Password -Path $UserPath -PassThru | Enable-ADAccount
        if ($User -eq "<XXX>") #The account you want to use for Opsmgr Action Account
        {
            Add-ADGroupMember $Group -Members $User
        }
        if ($User -eq "<XXX>") #The account you want to use for Opsmgr Data Access
        {
            Add-ADGroupMember $Group -Members $User
        }
    }
}