user photo
> Merl: ```powershell
import-module activedirectoryAdd-Type -AssemblyName System.Drawing
$folderPath = "C:\Temp"
$SourcePath = "\\fs-01\D$\Common\Фотографии сотрудников\"
# Get all image files from the specified folder
Get-ChildItem -Path $SourcePath -File | Rename-Item -NewName {$_.Name -replace ".png", ".jpg" }
Get-ChildItem -Path $SourcePath -File | Rename-Item -NewName {$_.Name -replace ".jpeg", ".jpg" }
Get-ChildItem -Path $SourcePath -File| Copy-Item -Destination $folderPath -Force
$imageFiles = Get-ChildItem -Path $folderPath -File|Where-Object {(($_.Name -Like "*.jpeg") -or($_.Name -Like "*.jpg") -or($_.Name -Like "*.png"))}
$csizeW = 640
$csizeH = 640
# Loop through each image file
foreach ($imageFile in $imageFiles) {
# Load the image using .NET framework
$image = [System.Drawing.Image]::FromFile($imageFile.FullName)
$ratioX = $csizeW / $image.Width
$ratioY = $csizeH / $image.Height
$ratio = $ratioY
if($ratioX -le $ratioY)
{
$ratio = $ratioX
}
$newWidth = [int] ($Image.Width*$ratio)
$newHeight = [int] ($Image.Height*$ratio)
# Create a new bitmap with the desired size
$resizedImage = New-Object System.Drawing.Bitmap($newWidth, $newHeight)
# Create a graphics object from the new bitmap
$graphics = [System.Drawing.Graphics]::FromImage($resizedImage)
# Set the interpolation mode for better resizing quality
$graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
# Draw the original image onto the new bitmap with resizing
$graphics.DrawImage($image, 0, 0, $newWidth, $newHeight)
# Dispose the objects to free up resources
$graphics.Dispose()
$image.Dispose()
# Save the resized image in the same file format
$resizedImagePath = Join-Path -Path $folderPath -ChildPath ($imageFile.BaseName + "_resized" + $imageFile.Extension)
$resizedImage.Save($resizedImagePath,([System.Drawing.Imaging.ImageFormat]::JPEG))
# Dispose the resized image object
$resizedImage.Dispose()
# Replace the original image with the resized image
Move-Item -Path $resizedImagePath -Destination $imageFile.FullName -Force
# Output the resized image path
Write-Output "Image replaced and resized: $imageFile"
}
cd $folderPath
$u = Get-ChildItem -filter *.jpg|select Basename
foreach ($User in $u)
{
$test = $user.BaseName
$photoname = $test + ".jpg"
$photo = [byte[]](Get-Content $photoname -Encoding byte)
Get-ADUser -Properties Description -Filter {Description -like $test} -SearchBase 'OU=DC=ru'|Set-ADUser -Replace @{thumbnailPhoto=$photo}
$user.BaseName
}
```
> Merl: Берет фото из папки пережимает, сравнивает имена фот с дисплейнэймом, пихает в ад
Комментарии
Отправить комментарий