1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# パラメーター $TenantName = "vamdemicsystem.black" $ClientId = "3c0a11e5-xxxx-41b9-9cf8-530596b997b4" # Azure Active Directory に登録したアプリケーションのアプリケーション ID $ClientSecret = "FJdbZxxxxxxxxxxxxxxxxxxxxxxx2-u[" # Azure Active Directory に登録したアプリケーションのキー $SmtpAddress = "y-kujirai@vamdemicsystem.black" # アクセストークン取得 $Result = Invoke-RestMethod -uri "https://login.microsoftonline.com/$($TenantName)/oauth2/token" -Method Post -Body @{grant_type = "client_credentials"; resource = "https://graph.microsoft.com/"; client_id = $ClientId; client_secret = $ClientSecret } $Token = $Result.access_token # パラメータを設定 $Body = @{ "subject" = "歯医者" "body" = @{ "contentType" = "HTML" "content" = "予定本文" } "Start" = @{ "dateTime" = "2020-04-20T12:00:00" "timeZone" = "Tokyo Standard Time" } "End" = @{ "dateTime" = "2020-04-20T13:00:00" "timeZone" = "Tokyo Standard Time" } } # Jsonファイルへコンバート $JsonBody = ConvertTo-Json $Body -Depth 4 # UTF8へエンコーディング $EncodedBody = [System.Text.Encoding]::UTF8.GetBytes($JsonBody) # Post Invoke-WebRequest -Uri "https://graph.microsoft.com/v1.0/users/$SmtpAddress/calendar/events" -Headers @{Authorization = "Bearer " + $Token } -ContentType "application/json" -Body $EncodedBody -Method Post |