D
D
Dmitry Shumov2020-03-11 16:20:25
PowerShell
Dmitry Shumov, 2020-03-11 16:20:25

Powershell message encoding for the user. How?

Comrades, there is a piece of script that should display a message to all RDS users:

$ConnectionBroker = "MOS-RDS-BROKER.nasta.local"
$SessionHostCollection = "MS products delivery"

$MessageTitle = "Сообщение от тех.поддержки"
$MessageText = "Уважаемые коллеги!В связи с проведением технических работпросьба корректно завершить работу на RDS - в течении 10 минут сервер будет перезагружен!"

If ($ConnectionBroker -eq "") {
 $HAFarm = Get-RDConnectionBrokerHighAvailability
 $ConnectionBroker = $HAFarm.ActiveManagementServer
}

$Sessions = Get-RDUserSession -ConnectionBroker $ConnectionBroker -CollectionName $SessionHostCollection
$encoding = [System.Text.Encoding]::UTF8
ForEach ($Session in $Sessions) {
Send-RDUserMessage -HostServer $Session.ServerName -UnifiedSessionID $Session.UnifiedSessionID -MessageTitle $MessageTitle -MessageBody $MessageText -Encoding $encoding
}

The script that works, but a problem in the coding of the messages coming to users.
Tried to do like this:
$encoding = [System.Text.Encoding]::UTF8
Send-RDUserMessage -HostServer $Session.ServerName -UnifiedSessionID $Session.UnifiedSessionID -MessageTitle $MessageTitle -MessageBody $MessageText -Encoding $encoding

But it doesn't roll. Writes that: Send-RDUserMessage : A parameter cannot be found that matches parameter name 'Encoding'.
I tried to resave in a notepad with different encodings - the same bolt.
How to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
azarij, 2020-03-11
@azarij

and if you replace:

$MessageText = "Уважаемые коллеги!В связи с проведением технических работ просьба корректно завершить работу на RDS - в течении 10 минут сервер будет перезагружен!"

on the:
$MessageText =[System.Text.Encoding]::UTF8.GetString([System.Text.Encoding]::UTF8.GetBytes("Уважаемые коллеги!В связи с проведением технических работ просьба корректно завершить работу на RDS - в течении 10 минут сервер будет перезагружен!"))

as I understand it, in this way we will explicitly indicate that we want to store this string in UTF8.
if again there are question marks instead of the Russian text, replace utf8 with utf16.
You can also try to set up regional networking for non-Unicode programs on the receiving side and put Russia there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question