param($Path) #$Path = "C:\Temp\Scripts\Photo" $count = 0 $log = [io.path]::GetDirectoryName($MyInvocation.MyCommand.Path)+ "\" +[io.path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Path)+".log" Out-File -FilePath $log -InputObject (Get-Date -Format "dd-MM-yyy") -Encoding utf8 -Append if (!(Get-Module -Name ActiveDirectory)) { # Включить модуль import-module ActiveDirectory } if($Path -eq $null) { Out-File -FilePath $log -InputObject "Enter User Photo Path. Program will be terminated." -Encoding utf8 -Append exit } $DIR = [IO.Directory]::GetFiles($Path) foreach($File in $DIR) { if(([io.path]::GetExtension($File)) -eq ".jpg") { if(((Get-Item $File).length) -gt 10kb) { Out-File -FilePath $log -InputObject "Photo | $File | too large, try another one less than 10kb. Start working with the next picture." -Encoding utf8 -Append } else { $FileName = [io.path]::GetFileNameWithoutExtension($File) if((Get-ADUser -Identity $FileName -Properties thumbnailPhoto).thumbnailPhoto -eq $null) { Out-File -FilePath $log -InputObject "User $FileName has no photo. Starting write value." -Encoding utf8 -Append $Photo = [byte[]](Get-Content $File -Encoding byte) Set-ADUser -Identity $FileName -Replace @{thumbnailPhoto=$Photo} Out-File -FilePath $log -InputObject "User $FileName was edited, please check." -Encoding utf8 -Append $count = 1 } } } else { Out-File -FilePath $log -InputObject "Photo | $File | is not a picture. Start working with the next file." -Encoding utf8 -Append } } if($count -eq 0) { Out-File -FilePath $log -InputObject "No changes has been done." -Encoding utf8 -Append }