株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

# パラメーター
$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

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)