Created
July 13, 2018 02:20
-
-
Save vexx32/d02b61b4327b2f4594795ec9b794f0cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###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