Trying to test importing users via CSV. Running into the following error --
Error: The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
Here's the code I'm using --
$file = "c:\test\users.csv"
$targetDN = "%distinguishedName%"
$columnMap = @{
"Preferred First Name" = "givenName";
"EmployeeLastName" = "sn";
"Category_Location" = "physicalDeliveryOfficeName";
"Category_CostCenter" = "extensionAttribute1";
"Category_ServiceLine" = "department";
"Category_JobLevel" = "title";
}
$domain = $Context.GetObjectDomain($targetDN)
$importedUsers = Import-Csv $file
foreach ($user in $importedUsers)
{
$otherAttributes = @{}
foreach ($property in $user.PSObject.Properties)
{
# Map property name if mapping specified
if ($columnMap[$property.Name])
{
$propertyName = $columnMap[$property.Name]
$user.PSObject.Properties.Remove($property.Name)
}
else
{
continue
}
# Get property value
$value = $property.Value
if ([System.String]::IsNullOrEmpty($value))
{
continue
}
$otherAttributes.Add($propertyName, $value)
}
try
{
$user | New-AdmUser -Path $targetDN -Server $domain `
-AdaxesService localhost -ErrorAction Stop
}
catch [System.Exception]
{
$to = "me@company.com"
$subj = "Failed to Import User from CSV"
$bodyText = "Adaxes failed to import user " + $user.Name + " from $file."`
+ "`nError: " + $_.Exception.Message
$bodyHtml = $null
$Context.SendMail($to, $subj, $bodyText, $bodyHtml)
$Context.LogMessage($bodyText, "Error")
}
}
Here's an example CSV (comma separated, not semi-colon). I also tried modifying the CSV by removing any fields not mapped in the Powershell script, but no luck --
Here's my scheduled task --