0 votes

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 --

image.png

Here's my scheduled task --

image.png

by (110 points)

1 Answer

0 votes
by (272k points)

Hello,

We recommend you to use one of the scripts from the following article in our repository: https://www.adaxes.com/script-repository/import-new-and-updated-users-from-csv-file-s246.htm. It looks like Script 3: Only create new users is exactly what you need. In your case, the $ouDN variable should be set to %distinguishedName%.

$ouDN = "%distinguishedName%" # TODO: modify me
0

Thanks.

How would I go about excluding certain columns in the CSV from being processed by the script? Right now the script tries to process every column which spits out the following error -

The following properties are not defined in the directory schema: Scheduled Hours, EmployeeFirstName, Category_HireType, Full or Part Time and Hire Date.

Those columns don't matter for our purposes, so can I just map each of those to $null or something?

Related questions

0 votes
1 answer

Hi, I'm following the guide about scheduling a user import from a CSV file: Schedule Import of Users from CSV but I get the following error: *"The input object cannot ... <ScriptBlock>, <No file>: line 7". Any help would be much appreciated. Dario

asked Dec 17, 2019 by winstonsmith (40 points)
0 votes
1 answer

I am trying to make the amount of users using csv. I noticed when I use the "Manager" field of the error. Question1: How should I put the information? Initially I put the ... "Tony Stark". Question2: Can I import the users and set the group in the csv file?

asked Jun 18, 2019 by user1928 (550 points)
0 votes
1 answer

We are trying to get a scheduled task to run every Friday night at 10:00pm to pull the users needed to be fully deprovisioned by the custom command we have created.

asked Dec 2, 2016 by willy-wally (3.2k points)
0 votes
1 answer

Hi Support, We're trying Import Users from CSV. For the most Users it works fine, but for Users with Umlaut (ö,ü,ä, è, é,à, etc) the Import Service makes Symole? Is there a way Import Users with Umlaut in their Name? Thanks for your Help.

asked Nov 29, 2013 by Napoleon (700 points)
0 votes
1 answer

Hello, When running the supplied script for importing a user photo into AD we encounter the following error: Exception calling "SetInfo" with "0" argument(s): "A ... /www.adaxes.com/script-repository/import-user-photo-s244.htm Thank you for your assistance!

asked Oct 26, 2020 by sgordon213 (110 points)
3,351 questions
3,052 answers
7,794 comments
545,115 users