iT邦幫忙

1

PowerShell 發送訊息到 telegram

f530 2024-01-17 09:27:351186 瀏覽
  • 分享至 

  • xImage
  •  

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"

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

1
f530
iT邦新手 4 級 ‧ 2024-01-23 10:15:52

沒人留言也可以上熱門哈哈哈 我真他馬的無聊到爆><
我再來貼一下 ~~~~ 可以發送出來現在登入的電腦,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

我要留言

立即登入留言