Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Generate vCards using Active Directory

$
0
0

Since my company is hell-bent on using vCards, yet doesn’t take the time to keep them updated, I created this script that runs weekly and dumps all the vCards to a shared drive.

Data it pulls from AD:
Name
Company
Department
Title
Work phone number
Cell phone number
Physical address
Email address
Photo (from Exchange, but AD’s thumbnailPhoto attribute will work as well)

# Get & store admin credentials. The following two lines can be commented out after password is stored. $credentials = Get-Credential $credentials.Password | ConvertFrom-SecureString | Set-Content C:ScriptsvCardsExchangePassword.txt $exchangeAdmin = “admin@metacortex.com” $password = Get-Content C:ScriptsvCardsExchangePassword.txt | ConvertTo-SecureString $credentials = New-Object System.Management.Automation.PSCredential $exchangeAdmin, $password # Connect to Exchange $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mail.metacortex.com/PowerShell/ -Authentication Kerberos -Credential $credentials Import-PSSession $session # Get AD users from specified OU and build vCards Get-ADUser -SearchBase "OU=Users,OU=HQ,DC=ad,DC=metacortex,DC=com" -Filter {(Enabled -eq $true)} -Properties * | ForEach { # Assign filename variable based on user's name $filename = "C:ScriptsvCards" + $_.displayName + ".vcf" Remove-Item $filename -ErrorAction SilentlyContinue # Generate vCard Add-Content -Path $filename "BEGIN:VCARD" Add-Content -Path $filename "VERSION:2.1" Add-Content -Path $filename ("N;LANGUAGE=en-us:" + $_.sn + ";" + $_.givenName) Add-Content -Path $filename ("FN:" + $_.displayName) Add-Content -Path $filename ("ORG:" + $_.company + ";" + $_.department) Add-Content -Path $filename ("TITLE:" + $_.title) Add-Content -Path $filename ("TEL;WORK;VOICE:" + $_.telephoneNumber) Add-Content -Path $filename ("TEL;CELL;VOICE:" + $_.mobile) Add-Content -Path $filename ("ADR;WORK;PREF:" + ";;" + $_.streetAddress + ";" + $_.l + ";" + $_.st + ";" + $_.postalCode) Add-Content -Path $filename ("EMAIL;PREF;INTERNET:" + $_.mail) # Get high quality photo from Exchange and convert to Base64 $photo = Get-UserPhoto -Identity $_.Name -ErrorAction SilentlyContinue if ($photo -ne $null) {$photo = [convert]::ToBase64String($photo.PictureData)} Add-Content -Path $filename ("PHOTO;ENCODING=b;TYPE=JPEG:" + $photo) Add-Content -Path $filename "END:VCARD" } Remove-PSSession $session 

submitted by /u/Shoot2ill
[link] [comments]

The post Generate vCards using Active Directory appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images