Create and Configure Users for Synthetic Transactions


Submitted by Antenehe Temteme, Microsoft

 

 

This script will perform the following actions:

1.    Create Active Directory users

2.    Enable those users for Lync Server 2010

3.    Create health monitoring configuration for use with synthetic transactions when they are run from System Center Operations Manager (SCOM)

 

Copy the following script, paste it into Notepad (or your favorite script editor), and save it as CreatandConfigureSTUsers.ps1. (You can choose a different name, just be sure to use that name when calling the script; see the Usage section below.)

 

Script

Usage

Parameters

Examples

Output

 

Script

 

param(

    [string] $domainFqdn = $(Read-Host -prompt “Plaese Enter Domain FQDN”),

    [string] $poolFqdn = $(Read-Host -prompt “Plaese Enter Pool FQDN”),

    [string] $userPrefix = $(Read-Host -prompt “Plaese Enter User Prefix”),

    [string] $OUname,

    [switch] $EnableEnterpriseVoice = $false,

    [string] $User1telURI,

    [string] $User2telURI

     

    )

 

Import-Module Lync

##############################################################################################################################

#  This function takes Pool FQDN and returns the Pool’s short name

##############################################################################################################################

 

function GetPoolShortName([string]$poolFQDN)

{

   if(-not([String]::IsNullOrEmpty($poolFqdn)) -and $poolFqdn.Contains(“.”) )

   {

      [int] $index=$poolFqdn.IndexOf(‘.’)

      $poolName =$poolFqdn.SubString(0,$index)

      $poolName

   }

   else

   {

      $(throw “Pool FQDN can not be Empty or Pool FQDN is not in a valid format”)

   }

}

 

############################################################################################################################

#  This function accepts the Identity of user and registrar pool and enables the user for Lync Server

############################################################################################################################

 

function EnableUserforLS([string]$Identity,[string]$RegistrarPoolFQDN)

{

      try

      {

            Enable-CsUser -Identity $Identity -RegistrarPool $poolFqdn -SipAddressType UserPrincipalName

      }

      catch

      {

            $( throw “Exception encountered when trying to enable user for Lync Service ” -f $_.Exception.ToString())

      }

     

}

 

############################################################################################################################

#  This function accepts pool FQDN, first and second user sip uris and creates health monitoring configuration

############################################################################################################################

 

function CreateHealthMonitoringConfiguration([string]$poolFQDN,[string]$firstUserSipURI,[string]$secondUserSIPURI)

{

      try

      {

            New-CsHealthMonitoringConfiguration $poolFqdn -FirstTestUserSipUri $firstUserSipURI  -SecondTestUserSipUri $secondUserSIPURI

      }

      catch

      {

            $(throw “Exception encountered when trying to create health monitoring configuration ” -f $_.Exception.ToString())

      }

}

 

############################################################################################################################

#  This function accepts pool FQDN and verifies whether the pool is capable of hosting users or not

############################################################################################################################

 

function CheckPoolValidity($poolFQDN)

{

   if([String]::IsNullOrEmpty($poolFQDN))

   {

      $(throw “Pool FQDN can not be Empty.”)

   }

   else

   {

      $topo=Get-CsTopology

      foreach($cluster in $topo.Clusters)

      {

           

            [string] $pool=$cluster.Fqdn

            if($pool.ToLower() -eq $poolFqdn.ToLower())

            {    

                  $registrarService = $cluster.InstalledServices[[Microsoft.Rtc.Management.Core.RoleName]::Registrar]

                  return (($registrarService -ne $null) -and ($registrarService.IsDirector -eq $false))

            }

      }

   }

}

 

################################################################################################################################

#  Takes OUDN and User prefix and creates Disabled AD users, Enables the users for Lync Server for a pool and creates health

#  monitoring configuration

################################################################################################################################

 

function CreateADUserandEnableForLS([string]$OuDN , [string]$userName,[string]$lineURI)

{

    $ldpPath= “LDAP://” +  $OuDN

    $container= [ADSI]$ldpPath

    $container.psbase.Get_children()

   

    $usercommonName= “CN=” + $userName

      $newUser = $container.Create(“User”,$usercommonName )

      $newUser.Put(“sAMAccountName”, $userName)

      $newUser.Put(“name”, $userName)

      $dsecription= “ST Test Account ” + $userName + “for ” + $poolName

      $newUser.put(“description”, $dsecription )

      $newUser.put(“sAMAccountName”, $userName)

      $newUser.put(“givenName”, $userName)

      $newUser.put(“userPrincipalName”, $userName + “@” + $domainFqdn )

      $newUser.SetInfo()

    $newUser.psbase.InvokeSet(“AccountDisabled”, $false)

      $newUser.SetInfo()

    $newUser.SetPassword(“P@55w0rd”)

      $Identity=$usercommonName + “,” + $OuDN

      EnableUserforLS $Identity $poolFQDN

   

     

}

 

###############################################################################################################################

#  Takes pool FQDN and checks if health monitoring configuration exists for the pool or not

###############################################################################################################################

function HealthMonitoringConfigurationNotExists([string]$poolFqdn)

{

      $hms=Get-CsHealthMonitoringConfiguration

      $hmnotFound=$true;

      foreach($hm in $hms)

      {

            if($hm.Identity -eq $poolFqdn)

            {

                  $hmnotFound=$false

                  return

            }

Comments (2)
  1. Jonatan says:

    Hi

    Fist off, great script you have created!

    Im getting this error though, any ideas?

    Exception encountered when trying to enable user  for enterprise voice

    At C:CreateAndConfigureSTUsers.ps1:216 char:28

    +                     $(throw <<<<  "Exception encountered when trying to enabl

    e user  for enterprise voice" -f $_.Exception.ToString())

       + CategoryInfo          : OperationStopped: (Exception encou…nterprise v

      oice:String) [], RuntimeException

       + FullyQualifiedErrorId : Exception encountered when trying to enable user

        for enterprise voice

    The user is created and enabled for lync, but not enterprise voice. I can allways enable enterprise voice manually, but i dont know if thats the only thing missing..

    Thanks in advance 🙂

  2. Galappaththi says:

    Also missing "tel:" part on EV enabling section. Should be as below;

    –User1telURI tel:+14255551212 –User2telURI tel:+12065551234

Comments are closed.

Skip to main content