Forum Discussion

AwaisKhalid's avatar
AwaisKhalid
Copper Contributor
Aug 18, 2020
Solved

Create meeting Using PowerShell, Graph API and CSV File

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'}
}

  • 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

4 Replies

  • Manfred101's avatar
    Manfred101
    Iron Contributor

    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

      • Johnny-5's avatar
        Johnny-5
        Copper Contributor
        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"

Resources