I have not needed to write a script in a while, so I am ful of cobwebs and I need some help. I am trying to write a PowerShell script that will do the following:
- Read a list of about 50 names in the format Last,First from a text file.
- For each name, find the corresponding samAccountname based on the Display Name
- Change the Thumbnail picture associated with each name.
I got the meat of the script done, but just cannot seem to wrap my head around stuff I thought I knew - i.e. - the Foreach Loop and getting the names into the script.
Here is what i have so far:
Import-Module activedirectory
$filepath = "C:\Users\MJD\Pictures\NEWPHOTOS.txt"
$name = (Get-Content $filepath)
ForEach-Object
{
$ADUser = (Get-ADUser -Filter {DisplayName -like $name}).samAccountname
$PhotoLocation = "C:\Users\MJD\Pictures\" + $ADUser + ".jpg"
$photo = [byte[]](Get-Content $PhotoLocation -Encoding byte)
Set-ADUser $ADUser -Replace @{thumbnailPhoto=$photo}
}This seems to work when the text file NEWPHOTOS.txt only contains one name.
I cannot get this to work when I add a second name to the list.
Matt Dillon