[ngw] Scripts to prepare and upload pictures to GroupWise 2014 R2 --> Cool Tools

Morris Blackham mblackham at microfocus.com
Tue Feb 2 21:31:18 UTC 2016


And if you are in the AD boat,  here's a PS script to do basically the same thing Mathias script does,  except for the image manipulation.   This one will store photo to AD and then sync pic to GW if user is associated.  

--Morris
___________________________________________________________


#***********  Import photo to AD and sync photo to GW associated user ********
#
# This script uses data from a CSV file to import photos to Active Directory users
# syncs the photo to a GroupWise account that is associated to Active Directory.
#
# The CSV file must have at least 2 columns with header rows
#		 1) header row of 'sam', which is the users samAccountName
#	 	2) header row of 'photo', which is the path to
# the photo for the user.  The CSV file can contain additional columns, but the 2 
# mentioned above are required.  Example:
#
#	 givenName,surname,sam,photo
#	 Frank,Burns,frank,e:\tv\burns.jpg
#	 Gomer,Pyle,gomer,e:\tv\gomer.jpg
#
# The script will prompt for GroupWise admin service information to connect to the
# GroupWise Admin REST API.  You can use either the 'super' admin account or another
# system administrator.
#
# It will then prompt for which Active Directory attribute to store the photo.  The
# two options are jpegPhoto or thumbnailPhoto.  Keep in mind that the thumbnailPhoto
# attribute has a file size limit of 100k.  There is no size restriction on the jpegPhoto
# attribute.  Make sure that the GroupWise AD definition in System | LDAP Servers has the 
# corresponding attribute set for the "LDAP image attribute" setting.
#
# Must be executed from a Windows machine that has the ActiveDirectory PS module and logged
# in as AD user with appropriate permissions to add attributes to AD.
#

import-module ActiveDirectory

$csvFile = Read-Host -Prompt "Enter Path to CSV file: "

if (Test-Path $csvFile) {
    $rows = import-csv $csvFile
    }
else {
    Write-Host "CSV file not found.  Try again"
    Exit
}
#************* Prompt and define variables for GroupWise Admin service *****************
$gwHost = Read-Host "GroupWise admin service IP/Hostname"
$gwPort = Read-Host "GroupWise admin service Port"
$gwAdmin = Read-Host "GroupWise system administrator"
$gwPwd = Read-Host "Password for" $gwAdmin
$baseUrl = "https://${gwHost}:${gwPort}"

#*** Create Credentials in the correct form (Base64 encoded and UTF8) *
$encoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($gwAdmin+":"+$gwPwd ))  
$headers = @{Authorization = "Basic "+$encoded}

#********** Ignore self signed certs from GW admin service ************************************
add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
	    public bool CheckValidationResult(
		    ServicePoint srvPoint, X509Certificate certificate,
		    WebRequest request, int certificateProblem) {
		    return true;
		    }
	    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

#*************  Prompt for AD photo Attribute *************************
$title = "Select Photo Attribute"
$message = "Choose attribute to store photo"
$jpeg = New-Object System.Management.Automation.Host.ChoiceDescription "&jpegPhoto", `
    "photos will be added to the jpegPhoto attribute."
$thumb = New-Object System.Management.Automation.Host.ChoiceDescription "&thumbnailPhoto", `
    "photos will be added to the thumbnailPhoto attribute."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($jpeg, $thumb)
$result = $host.ui.PromptForChoice($title, $message, $options, 0) 
switch ($result)
    {
	    0 {"jpegPhoto was selected."
		    $attribute = "jpegPhoto"
		  }

	    1 { "thumbnailPhoto was selected"
		  $attribute = "thumbnailPhoto"
		  }
    }

Write-Host " "

# ****************** Iterate through CSV data **************
#   1. Get user object from AD; add photo
#   2. Search GW for user based on the user's DN
#   3. Send a sync picture request to GW admin service

foreach ($row in $rows) {
    try {
	    $aduser = Get-Aduser -Identity $row.sam -Properties * -ErrorAction Continue
	    }
    catch {
	 $_.Exception.Message
	 write-host " "
	 Continue
	 }

    $photo = [byte[]](Get-Content $row.photo -Encoding byte)
    Set-ADUser $aduser -Replace @{$attribute=$photo}
    write-host "Added photo to" $aduser.DistinguishedName
    
    $searchUrl = $baseUrl + "/gwadmin-service/list/user?ldapDn=" + $aduser.DistinguishedName
    $gwUser = Invoke-RestMethod -Uri $searchUrl -Headers $headers -Method GET

    if ($gwUser.list.resultInfo.outOf -eq 1) {
	    $syncUrl = $baseUrl + $gwUser.list.object.url + "/directorylink/syncpicture"
	    $sync = Invoke-RestMethod -Uri $syncUrl -Headers $headers -Method POST
	    write-host  "Photo synchronized to GroupWise for" $gwUser.list.object.name
    }
    else {
	    write-host "GroupWise user not found or is not associated to Active Directory"
    }

    write-host " "
}
_______________________________________________________________________________________________________________
>>> Mathias Faust <Mathias.Faust at gruner.ch> 2/1/2016 12:48 PM >>>
Hi all,

good news for all those who are interested in the scipts to resize and upload pictures to eDir / GroupWise. The scripts and rpms for SLES 11 SP3 / OES 11 SP3 are now online on Cool Tools:
https://www.novell.com/communities/coolsolutions/cool_tools/scripts-prepare-upload-pictures-groupwise-2014-r2/


Hope it works for you. If you have questions ask me and I'll try to answer.

kind regards
Mathias


Haftungsausschluss: 
Diese E-Mail enthaelt u.U. vertrauliche und/oder rechtlich geschuetzte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtuemlich erhalten haben, informieren Sie bitte den Absender und vernichten Sie diese E-Mail.
Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail sind untersagt.
Diese E-Mail wurde durch unseren MAILsweeper geprueft. Weder die Gruner Gruppe noch der Sender koennen zur Verantwortung gezogen werden fuer defekte Daten infolge von Viren oder Uebermittlungsfehlern.
_______________________________________________
ngw mailing list
ngw at ngwlist.com
http://ngwlist.com/mailman/listinfo/ngw




More information about the ngw mailing list