# -*- coding: utf-8 -*-

name = 'create-multiple-user'
description = 'Create multiple user object in AD'
args = {
	'user-prefix': dict(help='Name of the user'),
        'user-amount':dict(help='Number of users to created'),
	'user-password': dict(help='Password of the user', default='Univention.99'),
	'group': dict(help='Add user to this group'),
}

ps = '''
$ErrorActionPreference = "Stop"
$password =  "%(user_password)s"| ConvertTo-SecureString -asPlainText -Force
$group = "%(group)s"
$amount=%(user_amount)s/1
for($i = 1 ; $i -le $amount; $i++)
{
$description = "winrm testuser $i"
New-ADUser -Name "%(user_prefix)s$i" -ChangePasswordAtLogon 0 -Description "$description" -AccountPassword($password) -PassThru | Enable-ADAccount
Get-ADUser "%(user_prefix)s$i" -Properties Enabled | Format-Table  Name, Enabled
if ($group -ne "None") {
	Add-ADGroupMember "%(group)s" –Member "%(user_prefix)s$i"
}
}
'''
