0 votes

We are using the following the script and would like to have it updated to use a CSV file instead of the list option.
Thank you in advance for your assistance.

$basePropertyName = "departmentNumber" # TODO: modify me
$valueMap = @{
"0005" = @{ "l" = "Farmington"; "st" = "CT"; };
"0019" = @{ "l" = "Seekonk"; "st" = "MA"; };
"0021" = @{ "l" = "Fall River"; "st" = "MA"; };
"0030" = @{ "l" = "Fairfield"; "st" = "CT"; };
"0033" = @{ "l" = "Stratford"; "st" = "CT"; };
"9999" = @{ "l" = "DoNotRemove"; "st" = "NY"; };

} # TODO: modify me. Example @{<base property value> = <Property map>}. 
# $valueMap = @{"0001" = @{"l" = "City"; "department" = "Dep1"; "st" = "State"}}

# Get base property value
try
{
    $baseValue = $Context.TargetObject.Get($basePropertyName)
}
catch
{
    return # Value not specified
}

# Update properties
$propertyMap = $valueMap[$baseValue]
if ([System.String]::IsNullOrEmpty($propertyMap))
{
    $Context.LogMessage("Properties to update not specified for '$baseValue' value", "Warning")
    return
}

$user = $Context.BindToObjectEx($Context.TargetObject.AdsPath , $True)
foreach ($item in $propertyMap.GetEnumerator())
{
    $user.Put($item.Key, $item.Value)
}

# Build department
$department = [System.String]::Format("{0}, {1} - {2}", @($propertyMap["l"], $propertyMap["st"], $baseValue)) # TODO: modify me
$user.Put("department", $department)

# Commit changes
try
{
    $user.SetInfo()
}
catch
{
    $Context.LogMessage("An error occurred when updating user. Error: " + $_.Exception.Message, "Warning")
}
by (3.2k points)

1 Answer

0 votes
by (272k points)
selected by
Best answer

Hello,

Find an updated script below:

$basePropertyName = "departmentNumber" # TODO: modify me
$baseColumnName = "ID" # TODO: modify me
$csvFilePath = "\\Server\share\MyFile.csv" # TODO: modify me

# Get base property value
try
{
    $baseValue = $Context.TargetObject.Get($basePropertyName)
}
catch
{
    return # Value not specified
}

# Import CSV
try
{
    $records = Import-Csv -Path $csvFilePath -ErrorAction Stop
}
catch
{
    $Context.LogMessage("An error occurred when importing CSV. Error: " + $_.Exception.Message, "Warning")
    return
}

# Search record in CSV
$record = $records | Where {$_.$baseColumnName -eq $baseValue}
if ($record -eq $NULL)
{
    $Context.LogMessage("Properties to update not specified for '$baseValue' value", "Warning")
    return
}
elseif ($record -is [System.Array])
{
    $Context.LogMessage("Found more than one record with value '$baseValue' in column '$baseColumnName'", "Warning")
    return
}

# Update properties
$user = $Context.BindToObjectEx($Context.TargetObject.AdsPath , $True)
foreach ($property in $record.PsObject.Properties)
{
    if ($property.Name -eq $baseColumnName)
    {
        continue
    }

    $user.Put($property.Name, $property.Value)
}

# Build department
$department = [System.String]::Format("{0}, {1} - {2}", @($record.l, $record.st, $baseValue)) # TODO: modify me
$user.Put("department", $department)

# Commit changes
try
{
    $user.SetInfo()
}
catch
{
    $Context.LogMessage("An error occurred when updating user. Error: " + $_.Exception.Message, "Warning")
}
0

Perfect, thank you as always.

Related questions

0 votes
1 answer

Is there a way for Adaxes to use a user's Microsoft 365 profile pictures instead of having to select a file on a per user basis?

asked Feb 1 by keneth.figueroa (20 points)
0 votes
1 answer

Receive "Index operation failed; the array index evaluated to null. Stack trace: at &lt;ScriptBlock&gt;, &lt;No file&gt;: line 104&gt;" and "Index operation failed; the ... $GroupName, $GroupDN." } } #foreach write-output "" Write-Output "" Stop-Transcript

asked Apr 14, 2022 by jbahou (20 points)
0 votes
1 answer

hello i'm new with Adaxes i'm try to creat schuadle task to import a spefice user list by thier username id after that just update City for them by bulk updating . kinly advise

asked Aug 29, 2023 by sudox (20 points)
0 votes
1 answer

Hallo Everyone I'm attempting to import a CSV list to Update Current users. I Used the Script 2 from Repostitory https://www.adaxes.com/script-repository/ ... "employeeNumber") # TODO: modify me Test file: sAMAccountName,employeeNumber, Peter.Muster,AB052

asked Jul 13, 2021 by Sandberg94 (340 points)
0 votes
1 answer

Hi, we have replaced our local Exchange server with installation of Exchange Management Tools (EMT) installed directly on Adaxes server. And my question is: How can I force ... this is how 'Set External Senders' option looks in Adaxes config Thanks in advance

asked Apr 1, 2023 by KIT (910 points)
3,346 questions
3,047 answers
7,772 comments
544,969 users