Change 2010 GAL vcard export script

Change 2010 GAL vcard export script To spherical out the Vcard export scripts as many individuals are nonetheless working Change 2010 this is a Distant powershell script that may let you export Mailboxes (or contacts) from Energetic listing to Vcards and likewise embrace the GAL Photograph from the AD thumbnail property if set.

 The script makes use of the Get-Consumer Change Administration Shell cmdlet to get all of the Mailboxes particulars to incorporate within the Vcard file and likewise use LDAP to learn the AD thumbnailPhoto (if its been set).

earlier than you run this script be sure to set the next variable to the listing you need the vcards exported to

$exportFolder = “c:temp”

You might want to run this script from throughout the Change Administration Shell or a Distant Powershell session

I’ve put a download of this script right here the code appears like

  1. $exportFolder = “c:temp” 
  2. $Mailboxes = Get-Consumer -RecipientTypeDetails UserMailbox  
  3. foreach($Mailbox in $Mailboxes){ 
  4.     strive{     
  5.          
  6.         $DisplayName = $Mailbox.DisplayName; 
  7.         write-host(“Processing ” + $DisplayName) 
  8.         $fileName =  $exportFolder + $DisplayName + “” + [Guid]::NewGuid().ToString() + “.vcf 
  9.         add-content -path $filename “BEGIN:VCARD 
  10.         add-content -path $filename “VERSION:2.1 
  11.         $givenName = $Mailbox.FirstName 
  12.         $surname = $Mailbox.LastName 
  13.         add-content -path $filename (“N:” + $surname + “;” + $givenName) 
  14.         add-content -path $filename (“FN:” + $Mailbox.DisplayName) 
  15.         $Division = $Mailbox.Division; 
  16.         add-content -path $filename (“EMAIL;PREF;INTERNET:” + $Mailbox.WindowsEmailAddress) 
  17.         $CompanyName = $Mailbox.Firm 
  18.         add-content -path $filename (“ORG:” + $CompanyName + “;” + $Division)  
  19.         if($Mailbox.Title -ne ““){ 
  20.             add-content -path $filename (“TITLE:” + $Mailbox.Title) 
  21.         } 
  22.         $Nation = “ 
  23.         $Metropolis = “ 
  24.         $Road = “ 
  25.         $State = “ 
  26.         $PCode = “ 
  27.         if($Mailbox.Metropolis -ne ““){ 
  28.             $Metropolis = $Mailbox.Metropolis 
  29.         } 
  30.         if($Mailbox.StateOrProvince -ne ““){ 
  31.             $State = $Mailbox.StateOrProvince 
  32.         } 
  33.         if($Mailbox.StreetAddress -ne ““){ 
  34.             $Road = $Mailbox.StreetAddress 
  35.         } 
  36.         if($Mailbox.CountryOrRegion -ne ““){ 
  37.             $Nation = $Mailbox.CountryOrRegion 
  38.         } 
  39.         if($Mailbox.PostalCode -ne ““){ 
  40.             $PCode = $Mailbox.PostalCode 
  41.         } 
  42.         $addr =  “ADR;WORK;PREF:;” + $Nation + “;” + $Road + “;” +$Metropolis + “;” + $State + “;” + $PCode + “;” + $Nation 
  43.         add-content -path $filename $addr 
  44.         if($Mailbox.MobilePhone -ne ““){ 
  45.             add-content -path $filename (“TEL;CELL;VOICE:” + $Mailbox.MobilePhone)                   
  46.         } 
  47.         if($Mailbox.Cellphone -ne ““){ 
  48.             add-content -path $filename (“TEL;WORK;VOICE:” + $Mailbox.Cellphone) 
  49.         } 
  50.         if($Mailbox.Fax -ne ““){ 
  51.             add-content -path $filename (“TEL;WORK;FAX:” + $Mailbox.Fax) 
  52.         } 
  53.         if($Mailbox.HomePhone -ne ““){ 
  54.             add-content -path $filename (“TEL;HOME;VOICE:” + $Mailbox.HomePhone) 
  55.         } 
  56.         if($Mailbox.WebPage -ne ““){ 
  57.             add-content -path $filename (“URL;WORK:” + $Mailbox.WebPage) 
  58.         } 
  59.         Strive{ 
  60.                 $sidbind = “LDAP://<SID=” + $Mailbox.Sid + “> 
  61.                 $userObj = [ADSI]$sidbind 
  62.                 $photograph = $userObj.thumbnailPhoto.worth 
  63.                 if($photograph -eq $null){“No Photograph“} 
  64.                 if($photograph -ne $null){ 
  65.                     add-content -path $filename “PHOTO;ENCODING=BASE64;TYPE=JPEG: 
  66.                     $ImageString = [System.Convert]::ToBase64String($photograph,[System.Base64FormattingOptions]::InsertLineBreaks) 
  67.                     add-content -path $filename $ImageString 
  68.                     add-content -path $filename “`r`n”   
  69.                 } 
  70.         } 
  71.         catch{ 
  72.          
  73.         }    
  74.         add-content -path $filename “END:VCARD 
  75.         “Exported ” + $filename   
  76.     }  
  77.     catch{  
  78.     }  
  79. }  
Tags:

Rate this article!

Related Posts

Leave a Reply