简体   繁体   中英

Populate Azure AD User Properties From CSV

I am modifying batches of user properties based on the contents of a .csv. the csv contains an ObjectID which I use to identify a specific user and the value I want the property set to. (see Below)

ObjectID,Property2,Property3
1,John,smith
2,Jane,Doe

The Issue I am experiencing is "the property 'Property2' cannot be found on this object." I get a similar error for all the variables I am trying to set. I feel I am missing something really simple, but I simply don't know what it is. My code can be found below. Any assistance is appreciated.

Connect-AzureAD
$Csv = Import-Csv -Path "C:\1\2\3\4\Example.Csv" |ForEach-Object {
    $User.ObjectID = $Csv | Select ObjectID
    $User.Property2 = $Csv | Select Property2
    $User.Property3 = $Csv | Select Property3

    Set-AzureADUser -ObjectID $User.ObjectID -Property3 $User.Property3 -Property2 $User.Property2
}

@Bpengu

The other approach in addition to Theo had mentioned using the Automatic variable . The concept is almost same as above it iterates through each object (each row).

$users = Import-Csv -Path "C:\1\2\3\4\Example.Csv"
foreach ($user in $users)
{
Set-AzureADUser -ObjectID $user.ObjectID -Property3 $user.Property3 -Property2 $user.Property2
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM