Create a Virtual Business Card Using PowerShell & Graph API (Part 1)


 
With everyone working from home, many introductions are being made virtually these days. Since we can't trade business cards in person, why not digitally? Outlook provides the ability to create a contact card (VCard) for each of your contacts, including one for yourself. This could be beneficial for Sales or HR employees that are still generating sales leads or hiring new employees.

Many people don't know how to create their own, so this script creates one automatically for each person in a given AD OU. We can use AD properties for the name, phone, mobile, location, and other pertinent info. In addition, Graph API provides a picture that can be saved and converted to a base64 string for the VCard. 

Kinda neat, right? Check out my GitHub for a link to the script.

I've already written another script that will connect to SharePoint and upload each VCard to a library. From there, I've created a form attached to a flow in Power Automate. Once the form is submitted, the flow emails the VCard from SharePoint as an attachment that can be imported to a mobile phone. I'll cover the SharePoint script and Power Automate pieces in my next posts.

Create a Virtual Business Card Using PowerShell & Graph API (Part 2)


EDIT: I forgot to include instructions for obtaining the Graph API Access Token needed to run the script. The steps I used to get a token are listed below.

How to Get a Graph API Access Token

1)First, open the Microsoft Graph API Explorer and click the 'Sign in to Graph Explorer' button.




2) In the field to the left of the 'Run query' button enter the following string and modify the upn (user principal name) to your upn.

https://graph.microsoft.com/v1.0/users('upn@domain.com')/photo/$value


3) Leave the dropdown menu for the method type to 'GET' and the api version drop down menu to v1.0. Click the 'Run query' button to execute the query.

4) The query will run and should return the image of the person with the corresponding upn you entered in the 'Response preview' section. Underneath the fields in step 2, there are links for, 'Request body,' 'Request headers,' 'Modify permissions,' and 'Access token.'


5) Select 'Access Token' to get an access token you can use in the script. The copy button to the right of access token (arrow pointing) will allow you to copy the access token (which is quite long) to the script.




0 Comments