{"id":4225,"date":"2022-10-01T15:48:22","date_gmt":"2022-10-01T23:48:22","guid":{"rendered":"https:\/\/tungle.ca\/?p=4225"},"modified":"2023-03-13T17:33:47","modified_gmt":"2023-03-14T01:33:47","slug":"powershell-module-for-telegram","status":"publish","type":"post","link":"https:\/\/tungle.ca\/?p=4225","title":{"rendered":"PowerShell Module for Telegram"},"content":{"rendered":"\n<p>Credit for TechThoughts for this PowerShell module.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">https:\/\/www.techthoughts.info\/poshgram-powershell-module-for-telegram\/<\/code><\/pre>\n\n\n\n<p>Following a link below to install PoshGram &#8211; A PowerShell Module for Telegram<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/techthoughts2\/PoshGram\">https:\/\/github.com\/techthoughts2\/PoshGram<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell line-numbers\">#from a 6.1.0+ PowerShell session\n[Net.ServicePointManager]::SecurityProtocol =[Net.SecurityProtocolType]::Tls12\nInstall-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Scope AllUsers\nInstall-Module -Name \"PoshGram\" -Scope CurrentUser<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"811\" height=\"140\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image.png\" alt=\"\" class=\"wp-image-4226\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image.png 811w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-300x52.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-768x133.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-200x35.png 200w\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"804\" height=\"111\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-1.png\" alt=\"\" class=\"wp-image-4227\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-1.png 804w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-1-300x41.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-1-768x106.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-1-200x28.png 200w\" sizes=\"auto, (max-width: 804px) 100vw, 804px\" \/><\/figure>\n\n\n\n<p>PS script to install PoshGram in Windows machines.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell line-numbers\">$computers = get-content C:\\Scripts\\computers.txt\nforeach ($computer in $computers) {\n    invoke-command -ComputerName $computer -ScriptBlock {\n        if (-not(Get-InstalledModule PoshGram -Erroraction SilentlyContinue)) {\n            #from a 6.1.0+ PowerShell session\n            [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n            Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Scope AllUsers\n            Install-Module -Name \"PoshGram\" -Scope CurrentUser\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"268\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-28-1024x268.png\" alt=\"\" class=\"wp-image-4270\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-28-1024x268.png 1024w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-28-300x79.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-28-768x201.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-28-200x52.png 200w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-28.png 1123w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Check PoshGram has been installed in Windows machines.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">#Check PoshGram has been successfully installed in Windows machines\n$computers = get-content C:\\Scripts\\computers.txt\nforeach ($computer in $computers) {\n    invoke-command -ComputerName $computer -ScriptBlock {\n        Get-InstalledModule -name PoshGram\n    }\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"205\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-29-1024x205.png\" alt=\"\" class=\"wp-image-4271\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-29-1024x205.png 1024w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-29-300x60.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-29-768x154.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-29-200x40.png 200w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-29.png 1167w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Below is a PS code to send a message from PS to Telegram<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">#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\n$token = \u201c#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx\u201d\n$chat = \u201c-#########\u201d\n$test = \"I am a test\"\n&amp; '.\\Program Files\\PowerShell\\6-preview\\pwsh.exe' -command \"&amp; {Import-Module PoshGram;Send-TelegramTextMessage -BotToken $token -ChatID $chat -Message '$test';}\"\n#--------------------------------------------------------------------------<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">cd C:\\Program Files\\PowerShell\\7\n$token = \"965385337:AAH9FHX92cHcMdkR8y2olckKUJtpdHAMfCA\"\n$chat = \"824628585\"\nSend-TelegramTextMessage -BotToken $token -ChatID $chat -Message \"Test from 5.1 calling 7+ to\"<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"119\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-2-1024x119.png\" alt=\"\" class=\"wp-image-4228\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-2-1024x119.png 1024w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-2-300x35.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-2-768x89.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-2-200x23.png 200w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-2.png 1281w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Checking the Test message in your Telegram channel.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1018\" height=\"98\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-4.png\" alt=\"\" class=\"wp-image-4230\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-4.png 1018w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-4-300x29.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-4-768x74.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2022\/10\/image-4-200x19.png 200w\" sizes=\"auto, (max-width: 1018px) 100vw, 1018px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Credit for TechThoughts for this PowerShell module. Following a link below to install PoshGram &#8211; A PowerShell Module for Telegram https:\/\/github.com\/techthoughts2\/PoshGram PS script to install PoshGram in Windows machines. Check PoshGram has been installed in Windows machines. Below is a PS code to send a message from PS to Telegram Checking the Test message in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,7],"tags":[10,12],"class_list":["post-4225","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-powershell","tag-microsoft","tag-powershell"],"_links":{"self":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/4225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4225"}],"version-history":[{"count":11,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/4225\/revisions"}],"predecessor-version":[{"id":4300,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/4225\/revisions\/4300"}],"wp:attachment":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}