LoginSignup
9
12

More than 5 years have passed since last update.

PowerShell から LINE Notify を送る

Last updated at Posted at 2016-11-05

準備

[超簡単]LINE notify を使ってみる
こちらの記事を参考にしてトークンを取得します。(とても参考になりました)
なお、今回の実行環境は Windows 10/PowerShell5.0 です。

サンプル

以下、簡単なサンプルです。

linenotify.ps1
# パラメータ設定
# Line Notify エンドポイント
$uri    =  "https://notify-api.line.me/api/notify"

# トークン
$token  = "Bearer 取得したトークン"

# トークンをリクエストヘッダ内Authorizationに指定
$header = @{Authorization=$token}

# POSTパラメータにメッセージを指定
$body   = @{message="PowerShell から LINE Notify"}

# ★リクエスト実行
$res = Invoke-RestMethod -Uri $uri -Method Post -Headers $header -Body $body 

# デバッグ用結果表示
echo $res

実行結果

image.png
無事に送られてきました。

なお、 echo $res の部分では、正常時に以下の表示がされます。

status message
------ -------
   200 ok     

$res.status$res.message のようにアクセスできるのも便利です。

おわりに

簡単にできて、Windows 標準で実現可能なので、活用ができるのではないでしょうか。

9
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
12