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