SOLVED

Create meeting Using PowerShell, Graph API and CSV File

Copper Contributor

I have successfully created the teams meeting using Graph API and PowerShell. Now i wan to import a csv and want to create meeting using that csv file. There are two columns in csv DisplayName and UPN. Can anyone please help me with this


Import-Csv -Path "C:\Users\Awais\OneDrive - CS\Desktop\GraphAPI.csv" | foreach {
$apiUrl = "https://graph.microsoft.com/v1.0/me/events"
$bodyy = @'
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does noon work for you?"
},
"start": {
"dateTime": $_.StartTime,                                #Want to use csv data here
"timeZone": "Pakistan Standard Time"
},
"end": {
"dateTime": $_.EndTime,                                    #Want to use csv data here
"timeZone": "Pakistan Standard Time"
},
"location":{
"displayName":$_.DisplayName                      #Want to use csv data here 
},
"attendees": [
{
"emailAddress": {
"address":$_.UPN,                                            #Want to use csv data here
"name": "Awais Khalid"
 },
"type": "required"
 }
 ],
 "allowNewTimeProposals": true,
 "isOnlineMeeting": true,
 "onlineMeetingProvider": "teamsForBusiness"
 }
 '@

$DataPOST = Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $apiUrl -Method POST -Body $bodyy -ContentType 'application/json'}
}

4 Replies
best response confirmed by AwaisKhalid (Copper Contributor)
Solution

@AwaisKhalid 

Try to use this body:

 

$bodyy = @"
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does noon work for you?"
},
"start": {
"dateTime": $($_.StartTime),
"timeZone": "Pakistan Standard Time"
},
"end": {
"dateTime": $($_.EndTime),
"timeZone": "Pakistan Standard Time"
},
"location":{
"displayName":$($_.DisplayName)
},
"attendees": [
{
"emailAddress": {
"address":$($_.UPN),                                            #Want to use csv data here
"name": "Awais Khalid"
 },
"type": "required"
 }
 ],
 "allowNewTimeProposals": true,
 "isOnlineMeeting": true,
 "onlineMeetingProvider": "teamsForBusiness"
 }
"@

 

Manfred de Laat

Thank You so much, That worked.
Kind Regards
@Manfred101 

Hey guys, I'm trying to mimic the $bodyy variable here to create an all-day appointment but I'm getting " Invoke-RestMethod : The remote server returned an error: (400) Bad Request".

Any help is much appreciated.

Thank you,

Johnny

Code:
$eventBody = @"
{
"originalStartTimeZone": "UTC",
"originalEndTimeZone": "UTC",
"subject": "Lets go for lunch",
"body": {
contentType: "HTML",
content: "Does noon work for you?"
},
"start": {
dateTime: "2021-06-22T12:00:00",
timeZone: "UTC"
},
"end": {
dateTime: "2021-06-23T12:00:00",
timeZone: "UTC"
},
"showAs": "oof",
"isAllDay": true,
"isReminderOn": false,
"type": "singleInstance"
}
"@

$newAppt = Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $apiUrl -Method POST -Body $eventBody -ContentType "application/json"

hello @AwaisKhalid  

 

Can you explain to me this script, i need exactly this manip 

1 best response

Accepted Solutions
best response confirmed by AwaisKhalid (Copper Contributor)
Solution

@AwaisKhalid 

Try to use this body:

 

$bodyy = @"
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does noon work for you?"
},
"start": {
"dateTime": $($_.StartTime),
"timeZone": "Pakistan Standard Time"
},
"end": {
"dateTime": $($_.EndTime),
"timeZone": "Pakistan Standard Time"
},
"location":{
"displayName":$($_.DisplayName)
},
"attendees": [
{
"emailAddress": {
"address":$($_.UPN),                                            #Want to use csv data here
"name": "Awais Khalid"
 },
"type": "required"
 }
 ],
 "allowNewTimeProposals": true,
 "isOnlineMeeting": true,
 "onlineMeetingProvider": "teamsForBusiness"
 }
"@

 

Manfred de Laat

View solution in original post