Skip to content

Instantly share code, notes, and snippets.

@vexx32
Created July 13, 2018 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexx32/d02b61b4327b2f4594795ec9b794f0cb to your computer and use it in GitHub Desktop.
Save vexx32/d02b61b4327b2f4594795ec9b794f0cb to your computer and use it in GitHub Desktop.
###COPY and find photos then move and copy to two locations then upload to exchange ##
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010;
$OU = "OU=domain,dc=com"
$MissingPhotos = Get-ADUser -SearchBase $OU -Filter * -Properties ThumbNailPhoto, SamAccountName, GivenName, Surname |
Where-Object ThumbnailPhoto -eq $null |
Select-Object SamAccountName, GivenName, Surname |
Sort-Object Surname, GivenName -Descending
foreach ($User in $MissingPhotos) {
$User = "$($User.GivenName)*$($User.Surname)"
$SearchPath = '\\Server\Share\Folder'
$CopyPath = '\\Server\Share\PhotoBackups'
$Photo = Get-ChildItem -Path $SearchPath -Recurse -File -Include "$User*_bw_crop.jpg"
if (-not $Photo) {
continue # skip over this one, there's no photo, restart loop with next user
}
$PhotoCopy = Copy-Item $Photo -Destination "C:\temp\photos\"
Copy-Item $Photo -Destination $CopyPath > $null # Extra copy
Set-UserPhoto -Identity $User.SamAccountName -PictureData ([System.IO.File]::ReadAllBytes($PhotoCopy.FullName)) -Confirm:$False
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment