Function 如下 大家參考 參考 我真他馬的太閒了~~~~
#~~~~~~~~~~~~~~~~~~SendtoTelegram_Function~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function sendtotelegram
{ $telegramBotApiToken = "Your Token Key"
$chatId = "Your Chat ID"
$baseUrl = "https://api.telegram.org/bot$telegramBotApiToken/"
$method = "sendMessage"
$queryParams = @{ chat_id = $chatId; text = $message }
$queryString = ""
foreach ($param in $queryParams.GetEnumerator()) {
$queryString += "&" + $param.Key + "=" + $param.Value
}
$queryString = $queryString.TrimStart('&')
$url = $baseUrl + $method + "?" + $queryString
$response = Invoke-RestMethod -Uri $url -Method Get
#$response
}
#~~~呼叫Function~~~~~
sendtotelegram -message "$message"
沒人留言也可以上熱門哈哈哈 我真他馬的無聊到爆><
我再來貼一下 ~~~~ 可以發送出來現在登入的電腦,IP,使用者 ~~~~
$ipAddress = (Test-Connection -ComputerName $env:COMPUTERNAME -Count 1).IPv4Address.IPAddressToString
Write-Host $ipV4.IPV4Address
$computer = $env:COMPUTERNAME
$username = $env:USERNAME
$message = "Computer name: $computer`nIP address:$ipAddress`nWindows Login User name:$username"
#$message = "Computer name: $computer + `nIP address: + $ipAddress + `nWindows Login User name:+ $username"
"---------------------"
#"$message"
Write-Host $message