none
Compare two .csv files to update the thumbnailphoto property in ADUC accurately RRS feed

  • General discussion

  • I have a list of users that I need to update the thumbnailphoto property in ADUC on.

    I have a .csv file of the user names and display names.

    I have a second .csv file with the folder location of the images to be uploaded.

    I want to automate the setting of the image but I want to make sure the correct image is being assigned to the correct account.

    this is what I have so far:

    $ADuser = Import-Csv "filepath"
    $Picture = Import-Csv "filepath"

    Set-ADUser $ADuser -Replace @{thumbnailPhoto=([byte[]](Get-Content $Picture -Encoding byte))}

    What I'm getting with the above script is an error:

    "Get-content : A parameter cannot be found that matches parameter name'Encoding' "

    The Script runs, if I do just 1 user account and point to one image file, but then I'd have to update the script for each file. I want to automate that by importing a .csv.

    I figure I need to do a loop or two; but I'm a powershell newb and searching all though technet I can't quite find what I'm looking for. Rather I can't get the piecemeal scripts that I've found to Frankenstein together to work correctly.

    My thoughts are I need to look I need to look a my first .csv file to get the list of users that I'm changing.  Then I need to compare that first .csv file to the second .csv file to make sure the correct image be being assigned to the correct object.

    Guidance would be greatly appreciated, thank you.

    Tuesday, June 6, 2017 2:58 PM

All replies

  • Why two separate CSV files? I would create a single CSV file with two columns: One containing the sAMAccountName of the user and the other containing the path and filename of the thumbnail image for the user.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 6, 2017 3:57 PM
  • Do I have to specify in the script which column to reference in the .csv file?

    Set-ADUser $ADuser (column A) -Replace @{thumbnailPhoto=([byte[]](Get-Content $ADuser (column B)  -Encoding byte))}

    Tuesday, June 6, 2017 4:56 PM
  • Start by understanding what a CSV file is. CSV stands for "comma-separated values." Here is an example CSV file:


    "sAMAccountName","picturePath"
    "user1","d:\data\user1.png"
    "user2","d:\data\user2.png"
    "user3","d:\data\user3.png"
    

    The first line specifies the properties, and the subsequent lines are the data.

    If you have a text file with just lines of text in it, but the data is not comma-separated, then you don't really have a CSV file.

    When you use the Import-Csv cmdlet, PowerShell reads the data outputs an object for each row.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 6, 2017 5:03 PM
  • thank you,  I do know what a .csv file is I do have the document in a .csv file format.

    The questions I asked was:

    Do I have to specify in the script which column to reference in the .csv file?

    Set-ADUser $ADuser (column A) -Replace @{thumbnailPhoto=([byte[]](Get-Content $ADuser (column B)  -Encoding byte))}

    I'm reading another technet forum and I'm thinking I have to:

    # Import list of Users From CSV into $Userlist

    $UserList=IMPORT-CSV C:ImportsUsers.csv

    # Step through Each Item in the List

    FOREACH ($Person in $UserList) {

    # Build Username from First name and Last Initial

    $Username=$Person.Firstname+$Person.Lastname.substring(0,1)

    # Put our Domain name into a Placeholder, who wants all that typing?

    $Domain=’@blueville.local’

    # Build the User Principal Name Username with Domain added to it

    $UPN=$Username+$Domain

    # Create the Displayname

    $Name=$Person.Firstname+” “+$Person.Lastname

    # Create User in Active Directory

    NEW-QADUSER –FirstName $Person.Firstname –Lastname $Person.Lastname –Name $DisplayName $Name –SamAccountName $Username –UserPassword ‘1NewPassword’ –UserPrincipalName $UPN –Name $Name –ParentContainer ‘Blueville.local/Division/Contoso’

    }

     
    Tuesday, June 6, 2017 5:14 PM
  • What I am saying is that it would be much simpler to create a single CSV file, like the one in my previous message, and use that to update the user objects.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 6, 2017 5:18 PM
  • I did create a single .csv with samaccount name (column A) and the thumbnailPhoto (column B)

    Tuesday, June 6, 2017 5:22 PM
  • I did create a single .csv with samaccount name (column A) and the thumbnailPhoto (column B)

    Generally CSV files have a header line so you can identify the column by name rather than just "column A" or "column B", but sure, you can use a csv file like that with Set-ADUser to update Active Directory.

    If you are doing something and it is not working, you need to post:

    • The first few lines of your CSV text file
    • The exact command you are trying to use
    • The exact error message you are getting (if any)

    Try to ask a very precise and specific question.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 6, 2017 5:30 PM
  • here is now what I am working with

    $ADuser = IMPORT-CSV "filepath"

    # Step through Each Item in the List

    FOREACH ($Person in $ADuser) {

    # Build Username from First name and Last Initial

    $Username=$Person.sAMAccountName

    # Put picture into a place holder?

    $Picture=$pic.thumbnailPhoto

    # Create User in Active Directory

    Set-ADUser $ADuser -Replace @{thumbnailPhoto=([byte[]](Get-Content $Picture -Encoding byte))}

    }

    here is the error I am getting when I run this script

    Get-Content : Cannot bind argument to parameter 'Path' because it is null.
    At filepath:30 char:68
    + ... user -Replace @{thumbnailPhoto=([byte[]](Get-Content $Picture -Encodi ...
    +                                                          ~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Get-Content], ParameterBindingValidationExce 
       ption
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Power 
       Shell.Commands.GetContentCommand


    • Edited by thomwann Tuesday, June 6, 2017 6:17 PM
    Tuesday, June 6, 2017 6:06 PM
  • Change $Picture=$pic.thumbnailPhoto to $Picture=$Person.thumbnailPhoto
    Tuesday, June 6, 2017 6:19 PM