PowerShell Module for Telegram

Credit for TechThoughts for this PowerShell module.

https://www.techthoughts.info/poshgram-powershell-module-for-telegram/

Following a link below to install PoshGram – A PowerShell Module for Telegram

https://github.com/techthoughts2/PoshGram

#from a 6.1.0+ PowerShell session
[Net.ServicePointManager]::SecurityProtocol =[Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Scope AllUsers
Install-Module -Name "PoshGram" -Scope CurrentUser

PS script to install PoshGram in Windows machines.

$computers = get-content C:\Scripts\computers.txt
foreach ($computer in $computers) {
    invoke-command -ComputerName $computer -ScriptBlock {
        if (-not(Get-InstalledModule PoshGram -Erroraction SilentlyContinue)) {
            #from a 6.1.0+ PowerShell session
            [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
            Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Scope AllUsers
            Install-Module -Name "PoshGram" -Scope CurrentUser
        }
    }
}

Check PoshGram has been installed in Windows machines.

#Check PoshGram has been successfully installed in Windows machines
$computers = get-content C:\Scripts\computers.txt
foreach ($computer in $computers) {
    invoke-command -ComputerName $computer -ScriptBlock {
        Get-InstalledModule -name PoshGram
    }
}

Below is a PS code to send a message from PS to Telegram

#There is an example of calling PowerShell 6.1 from PowerShell 5.1 to send a Telegram message with PoshGram using dynamic variables in the message
$token = “#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx”
$chat = “-#########”
$test = "I am a test"
& '.\Program Files\PowerShell\6-preview\pwsh.exe' -command "& {Import-Module PoshGram;Send-TelegramTextMessage -BotToken $token -ChatID $chat -Message '$test';}"
#--------------------------------------------------------------------------
cd C:\Program Files\PowerShell\7
$token = "965385337:AAH9FHX92cHcMdkR8y2olckKUJtpdHAMfCA"
$chat = "824628585"
Send-TelegramTextMessage -BotToken $token -ChatID $chat -Message "Test from 5.1 calling 7+ to"

Checking the Test message in your Telegram channel.