Send messages via Telegram using PowerShell

PoshGram is a PowerShell module that enables you to send messages via the Telegram Bot API. PoshGram provides functionality to send various message types to a specified Telegram chat via the Telegram Bot API. Separate PowerShell functions are used for each message type. Checks are included to ensure that file extensions, and file size restrictions are adhered to based on Telegram requirements.

The Telegram Bot API requires very specific formatting criteria for Bot messaging. The goal of this project to abstract that complexity away in favor of simple and direct PowerShell functions.

PoshGram also opens up several programmatic use cases:

  • Custom scripts tied to task scheduler could alert you to potential system conditions
  • Test-LowDisk.ps1 tied to task scheduler -> leverages PoshGram to alert you if low disk condition found
  • Enable script to provide Telegram notifications
  • In a ForEach you could easily message multiple chat groups that your bot is a member of

Installation

Prerequisites

How to get the Telegram user ID?

Open Telegram,Type userinfobot in the search bar.

Then choose the userinfobot contact and click Start.

You will see your UserID as the userinfobot sent to you, thee number ID

Installing PoshGram via PowerShell Gallery

Installing PoshGram direct from GitHub

  • Create the following directory: C:\Program Files\WindowsPowerShell\Modules\PoshGram
  • Download Zip from GitHub
  • Extract files
  • Copy the extracted files into the created directory

Import the PoshGram module

Validate your Bot token ID

Send a basic Text Message

Send a photo message from a local source

Send a photo message from a URL source

Send a file message from a local source

Send a file message from a URL source

Note: In sendDocument, sending by URL will currently only work for gif, pdf and zip files.

Send a video message from a local source

Note: Telegram only supports mp4 videos.

Send a video message from a URL source

Note: Telegram only supports mp4 videos.

Send an audio message from a local source

Send an audio message from a URL source

Sending a telegram message from older versions of PowerShell

Thank you for spending some time at my site and in my blog. I hope you come to visit again soon 😉

About Lex van der Horst 192 Articles
Techwire

Be the first to comment

Leave a Reply