Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #WARNING: This module is unsupported and my corrupt your AD user object.
- #Jorgie
- <#
- .Synopsis
- Gets thumnailPhoto from and AD user object and saves it to the specified file
- .Parameter sAMAccountName
- The user objects sAMAccountName
- .Parameter OutputJpegFile
- The file to save the image (if any) to.
- .Parameter Server
- The AD server to talk to, if the user is not in the same domain as the local machine, a DC in the users domain must be provided.
- .Example
- Get-ADUsersThumbnailPhoto -sAMAccountName 'jorgie' -OutputJpegFile './jorgie.jpg'
- .Example
- Get-ADUsersThumbnailPhoto -sAMAccountName 'jorgie' -OutputJpegFile './jorgie.jpg' -Server 'col.missouri.edu'
- #>
- function Get-ADUsersThumbnailPhoto {
- param (
- [Parameter(Mandatory=$true)]
- [string]
- $sAMAccountName,
- [Parameter(Mandatory=$true)]
- [string]
- $OutputJpegFile,
- [Parameter(Mandatory=$false)]
- [string]
- $Server=$nul
- )
- Begin {
- if(!(Get-Module ActiveDirectory)) {
- Import-Module ActiveDirectory;
- if(!(Get-Module ActiveDirectory)) {
- throw 'Could not import ActiveDirectory module';
- }
- }
- }
- Process {
- if($Server -eq $null -or $Server.Length -lt 1) {
- $user = Get-ADUser -LDAPFilter "(sAMAccountName=$sAMAccountName)" -Properties thumbnailPhoto;
- } else {
- $user = Get-ADUser -LDAPFilter "(sAMAccountName=$sAMAccountName)" -Properties thumbnailPhoto -Server $Server;
- }
- if($user -eq $null) { throw 'Did not find a user.'; }
- if($user.thumbnailPhoto -eq $null) {
- throw 'That user does not seem to have a thumbnilPhoto.';
- }
- Set-Content -Encoding Byte -Path $OutputJpegFile -Value $user.thumbnailPhoto;
- }
- End {}
- }
- #test function
- #Get-ADUsersThumbnailPhoto -sAMAccountName 'jorgie' -OutputJpegFile './jorgie.jpg'
- <#
- .Synopsis
- Puts a jpg file into the thumbnailPhoto fields of an AD user object.
- .Parameter sAMAccountName
- The user objects sAMAccountName
- .Parameter InputJpegFile
- The file to get the image from. The image should be 128x128 or smaller and less than 10Kb in size.
- .Parameter Server
- The AD server to talk to, if the user is not in the same domain as the local machine, a DC in the users domain must be provided.
- .Example
- Put-ADUsersThumbnailPhoto -sAMAccountName 'jorgie' -InputJpegFile './jorgie.jpg'
- .Example
- Put-ADUsersThumbnailPhoto -sAMAccountName 'jorgie' -InputJpegFile './jorgie.jpg' -Server 'my.domain.com'
- #>
- function Set-ADUsersThumbnailPhoto {
- param (
- [Parameter(Mandatory=$true)]
- [string]
- $sAMAccountName,
- [Parameter(Mandatory=$true)]
- [string]
- $InputJpegFile,
- [Parameter(Mandatory=$false)]
- [string]
- $Server=$nul
- )
- Begin {
- if(!(Get-Module ActiveDirectory)) {
- Import-Module ActiveDirectory;
- if(!(Get-Module ActiveDirectory)) {
- throw 'Could not import ActiveDirectory module';
- }
- }
- }
- Process {
- if($Server -eq $null -or $Server.Length -lt 1) {
- $user = Get-ADUser -LDAPFilter "(sAMAccountName=$sAMAccountName)" -Properties thumbnailPhoto;
- } else {
- $user = Get-ADUser -LDAPFilter "(sAMAccountName=$sAMAccountName)" -Properties thumbnailPhoto -Server $Server;
- }
- if($user -eq $null) { throw 'Did not find a user.'; }
- [Byte[]]$imgBytes = Get-Content -Encoding Byte -Path $InputJpegFile;
- if($imgBytes.Length -gt 10240) { throw 'This script does not support images over 10Kb, the provided image was: ' + $jpgItem.Length + ' bytes.'; }
- if($Server -eq $null -or $Server.Length -lt 1) {
- Set-ADUser $user -Replace @{thumbnailPhoto=$imgBytes};
- } else {
- Set-ADUser $user -Replace @{thumbnailPhoto=$imgBytes} -server $Server;
- }
- }
- End {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement