Last active
May 21, 2022 15:05
-
-
Save tknhs/bc8554cbef4492a62650bb4943183e54 to your computer and use it in GitHub Desktop.
ユーザセッションがアクティブでない場合にLINEへ通知を送る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
セッション状態を確認するスクリプト | |
.DESCRIPTION | |
対象ユーザのセッションがアクティブでない場合にLINEへ通知を送る | |
.EXAMPLE | |
PS C:\Users> .\session-checker.ps1 -token xxxx -server test-server -user Administrator | |
... | |
.PARAMETER token | |
LINE Token | |
.PARAMETER server | |
サーバ名 | |
.PARAMETER user | |
セッション監視対象ユーザ名 | |
<CommonParameters> はサポートしていません | |
#> | |
################################################################################# | |
Param( | |
[parameter(mandatory=$true)][string]$token, | |
[parameter(mandatory=$true)][string]$server, | |
[string]$user = "Administrator" | |
) | |
$state = $null | |
# rdp | |
$session = query session | select-string $user | foreach { -split $_ } | select -index 3 | |
if ($session -eq "Active") { | |
$state = $session | |
} | |
# 切断 | |
$session = query session | select-string $user | foreach { -split $_ } | select -index 2 | |
if ($session -eq "Disc") { | |
$state = $session | |
} | |
# notify to line | |
if ($state -ne "Active") { | |
$uri = "https://notify-api.line.me/api/notify" | |
$header = @{Authorization = "Bearer $token"} | |
$body = @{message = "[$server] $user のセッションがアクティブでないためサーバを確認してください"} | |
Invoke-RestMethod -Uri $uri -Method POST -Headers $header -Body $body | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment