How to create user account in Active Roles using powershell script?

Hello All,

I have this script from your forum and adapted it a little, but it gives me this error below? Any help would be great. I also for some reason get a .ars file that exports to desktop when it completes. Ideally I would want for it to create the user in Active Roles once created and when this error below is fixed. Thank you.

ERROR:

Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'IndexOf'.
At C:\Users\lsc.jh6500\Desktop\NewBulkUsers.ps1:32 char:19
+ Write-Host "$($SourceData.IndexOf($NewUser)+1)\$($SourceData.Coun ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (IndexOf:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

\ - Creating TestTest_Build 

SCRIPT RUN:

Clear-Host
# -----------------------------------
# PARAMETERS OF SCRIPT YOU MAY MODIFY
# -----------------------------------
# Before using the script, modify the following constants
# PAth to a CSV file containing your users
$ImportPath = "$($env:USERPROFILE)\Desktop\NewUsers.csv"
# DN of the object to be copied
$ReferenceUserDN = "CN=cardiffhr,OU=Users Other,OU=CYTONE,OU=Sites,OU=Cytiva,OU=Organization,OU=LifeSciences,OU=Enterprise,DC=danaher,DC=org"
$UPNSuffix = "cytiva.com"

#---------------------------------------------------------------------------------
# Processing

# Import the list of users
$SourceData = Import-csv -Path $ImportPath

try
{
# Bind to source user
$SourceUser = [ADSI]"EDMS://$ReferenceUserDN"
#Bind to the source user's parent container
$ContainerObject = [ADSI]$SourceUser.Parent
}
catch
{
return
}

ForEach($User in $SourceData)
{
Write-Host "$($SourceData.IndexOf($NewUser)+1)\$($SourceData.Count) - Creating $($User.USerName)"
#Copy the source user
$NewUser = $ContainerObject.CopyHere("EDMS://$ReferenceUserDN", "CN=$($User.UserName)")

#Set the newly created user's properties
$NewUser.Put("givenName", "$($User.FirstName)")
$NewUser.Put("sn", "$($User.LastName)")
$NewUser.Put("sAMAccountName", "$($User.UserName)")
$NewUser.Put("userPrincipalName", "$($User.UserName)@$UPNSuffix")
$NewUser.Put("edsaPassword", "$($User.Password)")
$NewUser.Put("StreetAddress", "$($User.streetaddress)")
$NewUser.Put("Department", "$($User.department)")
$NewUser.Put("Title", "$($User.jobtitle)")
$NewUser.Put("Company", "$($User.company)")
#Commit changes
}

Thanks for your help!

Parents Reply Children
No Data