onPreCreate Script for naming Computer with PowerShell

Hello together,

i have the case that i want to create computers in a specific OU and want automatically create the name in the process. I have a virutal Attribute called "edsvaDeviceType" which describes if the device is a Laptop, Desktop or Tablet. Depending on this information i want to set the Name like N-001, T-001 or D-001 with the number always increasing (check if the device name already exists). I think this can be done with a onpreCreate but i do not get it to work.

In my form i have a first page where i set the device type but when i click "next" there is nothing set in the "Name" Property. Can you help me out here with an example?

function onPreCreate($Request)
{
$devicetype = $Request.Get("edsvaDeviceType")

if ($devicetype -eq "abc"){
$Request.Put("Name", "Bla")
$Request.SetInfo()
}

}

Thanks in advance,

Michael

  • onPreCreate will execute once the entire request has been submitted to Active Roles for processing. It sounds like you are wanting the information generated and then displayed back to the user after clicking 'Next' on a custom web form. For this you will need to use the function onGetEffectivePolicy. The code within it will be similar to what you have for onPreCreate, but to set the information on a specific attribute, instead of '$Request.Put' you can use lines like these:

    $Request.SetEffectivePolicyInfo("cn", $Constants.EDS_EPI_UI_GENERATED_VALUE, $Name)

    $Request.SetEffectivePolicyInfo("samaccountname", $Constants.EDS_EPI_UI_GENERATED_VALUE, $Name)

    Where $Name can be a unique name generated by some other code you have that generates the unique value earlier in the script based off of the edsvaDeviceType selected / entered.

  • Hi Richard!! Thanks a lot, it is working Slight smile