powershell

Powershellからcurlをたたく

今回はLINE投稿を行う例です

curl.exe -v -X POST $($conf.endpoint) `
  -H "Content-Type: application/json" `
  -H "Authorization: Bearer $($conf.Token)" `
  -d $body
エンドポイントやトークンを設定ファイルに
# config.psd1という名前で以下各種設定値を作成

@{
    endpoint= 'https://api.line.me/v2/bot/message/push'
    Token   = 'TokenDnyilFU='
    GroupId = 'C19c66d5'
}

# 設定ファイルを読み込む
$conf = Import-PowerShellDataFile ".\config.psd1"
$body = @{
to = $conf.GroupId
messages = @(
@{
type = "text"
text = "1つ目のメッセージです"
},
@{
type = "text"
text = "2つ目のメッセージです"
},
@{
type = "text"
text = "3つ目のメッセージです"
}
)
} | ConvertTo-Json -Depth 5

$body = @{
  to = $conf.GroupId
  messages = @(
    @{
      type = "flex"
      altText = "Disk Alert"
      contents = @{
        type = "bubble"
        body = @{
          type = "box"
          layout = "vertical"
          contents = @(
            @{ type="text"; text="⚠️ Disk Alert"; weight="bold"; size="xl" },
            @{ type="text"; text="SERVER01: 使用率 92%" },
            @{ type="text"; text="閾値: 90%" },
            @{ type="text"; text="対応をお願いします" }
          )
        }
      }
    }
  )
} | ConvertTo-Json -Depth 10
スポンサーリンク
タイトルとURLをコピーしました