Hello.
I'm fairy new with script on in Adaxes but like to make a business rule that moves computer to the correct OU and set an extended attribute with a numeric value.
I found that when we install a computer with Microsoft Configuration manager 2012R2 the computer account is created in AD and not Adaxes so we cannot use business rules.
Ok, I’ll make a script that I run on a schedule or interactively, maybe interactively within the instsallation process of Configruation Manager.
I make a script but it doesn’t work. I get an error that indicates that the script does not get the computer name from Adaxes.
The syntax of our computer names is. Site-Department-User-computer type. Ex. SV-IT-John-VM
import-module adaxes
$datornamn = $Context.TargetObject.Name #should return ‘SV-IT-John-VM’
$avdelning = [string]$datornamn.name.split('-')[1] #returns ’IT’
$datornamnAD = Get-AdmComputer $datornamn
#array with OU and costID
$OuLista = @(('IT','OU=IT,OU=Stod-Support,OU=Personal,OU=Company,DC=Company,DC=se',14),
@('dep1','OU=Fastighet,OU=Stod-Support,OU=Personal,OU=Company,DC=Company,DC=se',17),
….
@('dep15','OU=Personal,OU=Company-Assistans,DC=Company,DC=se',99)
)
$ou = $OuLista | where {$_[0] -match $avdelning}
if ($ou)
{
Move-AdmObject $datornamnAD -TargetPath $ou[1]
Set-AdmComputer $datornamnAD -add @{extensionattribute2=$ou[2]}
$loggtext = $datornamn.name " should be in OU "$ou[1] " mwith cosst ID "$ou[2]
$Context.LogMessage($loggtext, "Information")
}
else
{
$Context.LogMessage("Computer not placed in OU", "Information")
}
I don’t get any computer name in row 2. How do I get that.
Is there a smarter way to place computers in correct OU?