Answer the question
In order to leave comments, you need to log in
How to set up sending command output to Telegram?
Hello! I am new to PowerShell and I have the following code which is supposed to send a list of blocked users to telegram.
$token = "*******"
$chat_id = "********"
$text = Search-ADAccount -LockedOut | Select Name,SamAccountName
$URI = "https://api.telegram.org/bot" + $token + "/sendMessage?chat_id=" + $chat_id + "&text=" + $file
$Request = Invoke-WebRequest -URI ($URI)
Answer the question
In order to leave comments, you need to log in
He also writes that message text is empty, add the message to the variable (without spaces, so as not to create a new question):
$file="MyMessage"
"&text=" + $file
Telegram has another method for sending files.
If you need to send the contents of the file - then you first need to read it.
1. The Telegram API expects text from you, and you offer it an array of objects - that's why the error. You need to pass $text.Name and $text.SamAccountName, and do it in loop
2. You need to add the -UsersOnly parameter to Search-ADAccount - it will work faster, because will not check other types of AD objects (computers and service accounts)
3. There is a good example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question