# Invoke-restmethod encoding problem

**URL:** <https://forums.powershell.org/t/invoke-restmethod-encoding-problem/14823>\
**Category:** PowerShell Help\
**Created:** [August 19, 2020, 7:30am UTC](https://forums.powershell.org/t/invoke-restmethod-encoding-problem/14823 "2020-08-19T07:30:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dvidebaek](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@dvidebaek](https://forums.powershell.org/u/dvidebaek)\
**Post date:** [August 19, 2020, 7:30am UTC](https://forums.powershell.org/t/invoke-restmethod-encoding-problem/14823/1 "2020-08-19T07:30:43Z")

</div>

Hi Guys,

When i’m running the following Powershell code I get the wrong encoding. I need it to be in utf-8 but it’s not

[pre]$from = [xml](Invoke-RestMethod -Method Get -Uri (“[XMLTV | Honeybee.it](http://xmltv.xmltv.se/tv3.dk_2020-08-19.xml)”) -ContentType “text/xml”)

$from.tv.programme.desc [/pre]

I get these weird characters:

“De sÃ¸rgende enker”

“NÃ¥r LuksusfÃ¦lden til efterÃ¥ret vender tilbage”

In Denmark we use letters ÆØÅ 🙂

Do you guys know what i’m doing wrong? ![]()

&nbsp;

---

<div class="post-metadata">

**Author:** ![adminofthings](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@adminofthings](https://forums.powershell.org/u/adminofthings)\
**Post date:** [August 19, 2020, 8:42pm UTC](https://forums.powershell.org/t/invoke-restmethod-encoding-problem/14823/2 "2020-08-19T20:42:57Z")

</div>

You could test by adding `charset=utf-8` to your `-ContentType` value.

---

<div class="post-metadata">

**Author:** ![dvidebaek](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@dvidebaek](https://forums.powershell.org/u/dvidebaek)\
**Post date:** [August 21, 2020, 7:06am UTC](https://forums.powershell.org/t/invoke-restmethod-encoding-problem/14823/3 "2020-08-21T07:06:29Z")

</div>

[quote quote=251123]You could test by adding charset=utf-8 to your -ContentType value.

[/quote]  
It didn’t work I tried the following:

```
$from = [xml](invoke-restmethod -Method get -uri http://xmltv.xmltv.se/tv3.dk_2020-08-19.xml -ContentType "application/xml; Charset=utf-8")

$from.tv.programme.desc
```

One funny thing. When I ran the following code I didn't get the weird characters:

```
Invoke-RestMethod -Method Get -Uri ("http://xmltv.xmltv.se/tv3.dk_2020-08-19.xml") -ContentType "application/xml" -OutFile C:\users\[my user name]\OneDrive\Desktop\kanaler.xml
$XMLFile = Get-Content -Path C:\users\dvide\onedrive\desktop\kanaler.xml -Encoding UTF8
$XMLFile.tv.programme.desc
```

So I think there is something wrong in my script somewhere. Here is my "epg grabber script":

```
[DateTime]$StartDate = Get-Date [int]$SevenDays = 7 [DateTime]$EndDate = ($StartDate).AddDays($SevenDays)

$Channels = @{

‘animalplanet.discovery.dk’ = @{ ChannelName = ‘Animal Planet’ ChannelNumber = ‘28’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Animal\_Planet.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Animal_Planet.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Animal\_Planet.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Animal_Planet.png)’ } ‘canal9.dk’ = @{ ChannelName = ‘Canal 9’ ChannelNumber = 9 ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Canal\_9.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Canal_9.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Canal\_9.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Canal_9.png)’ } ‘ultrahd.viasat.dk’ = @{ ChannelName = ‘Viasat Ultra HD’ ChannelNumber = ‘38’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_Ultra\_HD.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_Ultra_HD.png)’ ProgrammeIcon = ‘’ } ‘series.viasat.dk’ = @{ ChannelName = ‘Viasat Series’ ChannelNumber = ‘24’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_Series.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_Series.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Viasat\_Series.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Viasat_Series.png)’ } ‘nature.viasat.dk’ = @{ ChannelName = ‘Viasat Nature’ ChannelNumber = ‘27’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_Nature.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_Nature.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Viasat\_Nature.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Viasat_Nature.png)’ } ‘history.viasat.dk’ = @{ ChannelName = ‘Viasat History’ ChannelNumber = ‘25’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_History.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_History.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Viasat\_History.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Viasat_History.png)’ }#\> ‘film.viasat.dk’ = @{ ChannelName = ‘Viasat Film Premiere’ ChannelNumber = ‘20’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_Film\_Premiere.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_Film_Premiere.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Viasat\_Film\_Premiere.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Viasat_Film_Premiere.png)’ } ‘hits.film.viasat.dk’ = @{ ChannelName = ‘Viasat Film Hits’ ChannelNumber = ‘22’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_Film\_Hits.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_Film_Hits.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Viasat\_Film\_Hits.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Viasat_Film_Hits.png)’ } ‘family.film.viasat.dk’ = @{ ChannelName = ‘Viasat Film Family’ ChannelNumber = ‘23’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_Film\_Family.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_Film_Family.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Viasat\_Film\_Family.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Viasat_Film_Family.png)’ } ‘action.film.viasat.dk’ = @{ ChannelName = ‘Viasat Film Action’ ChannelNumber = ‘21’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_Film\_Action.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_Film_Action.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Viasat\_Film\_Action.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Viasat_Film_Action.png)’ } ‘explorer.viasat.dk’ = @{ ChannelName = ‘Viasat Explore’ ChannelNumber = ‘26’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_Explore.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_Explore.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Viasat\_Explore.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Viasat_Explore.png)’ } ‘classic.vh1.se’ = @{ ChannelName = ‘VH1 Classic’ ChannelNumber = ‘34’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/VH1%20Classic.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/VH1%20Classic.png)’ ProgrammeIcon = ‘’ } ‘vh1.mtv.dk’ = @{ ChannelName = ‘VH1’ ChannelNumber = ‘33’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/VH1.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/VH1.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/VH1.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/VH1.png)’ } \<#‘2030.honeybee.it’ = @{ ChannelName = ‘TV4 Sverige’ ChannelNumber = ‘45’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV4\_Sverige.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV4_Sverige.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV4\_Sverige.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV4_Sverige.png)’ }#\> ‘tv3plus.dk’ = @{ ChannelName = ‘TV3+’ ChannelNumber = ‘4’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV3%2B.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV3%2B.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV3%2B.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV3%2B.png)’ } ‘one.tv3sport.dk’ = @{ ChannelName = ‘TV3 Sport’ ChannelNumber = ‘13’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV3\_Sport.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV3_Sport.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV3\_Sport.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV3_Sport.png)’ } ‘puls.tv3.dk’ = @{ ChannelName = ‘TV3 Puls’ ChannelNumber = ‘12’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV3\_Puls.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV3_Puls.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV3\_Puls.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV3_Puls.png)’ } ‘max.tv3.dk’ = @{ ChannelName = ‘TV3 Max’ ChannelNumber = ‘11’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV3\_Max.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV3_Max.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV3\_Max.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV3_Max.png)’ } ‘tv3.dk’ = @{ ChannelName = ‘TV3’ ChannelNumber = ‘3’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV3.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV3.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV3.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV3.png)’ } ‘zulu.tv2.dk’ = @{ ChannelName = ‘TV2 Zulu’ ChannelNumber = ‘7’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV2\_Zulu.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV2_Zulu.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV2\_Zulu.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV2_Zulu.png)’ } ‘sport.tv2.dk’ = @{ ChannelName = ‘TV2 Sport’ ChannelNumber = ‘14’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV2\_Sport.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV2_Sport.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV2\_Sport.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV2_Sport.png)’ } ‘news.tv2.dk’ = @{ ChannelName = ‘TV2 News’ ChannelNumber = ‘10’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV2\_News.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV2_News.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV2\_News.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV2_News.png)’ } ‘tv2.dk’ = @{ ChannelName = ‘TV2’ ChannelNumber = ‘2’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV2.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV2.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV2.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV2.png)’ } \<#‘2451.honeybee.it’ = @{ ChannelName = ‘TV2 Norge’ ChannelNumber = ‘47’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV2\_Norge.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV2_Norge.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV2\_Norge.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV2_Norge.png)’ }#\> ‘fri.tv2.dk’ = @{ ChannelName = ‘TV2 Fri’ ChannelNumber = ‘42’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV2\_Fri.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV2_Fri.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV2\_Fri.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV2_Fri.png)’ } ‘charlie.tv2.dk’ = @{ ChannelName = ‘TV2 Charlie’ ChannelNumber = ‘39’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TV2\_Charlie.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TV2_Charlie.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TV2\_Charlie.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TV2_Charlie.png)’ } ‘tlc.discovery.dk’ = @{ ChannelName = ‘TLC Danmark’ ChannelNumber = ‘40’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/TLC.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/TLC.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/TLC.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/TLC.png)’ } \<#‘1969.honeybee.it’ = @{ ChannelName = ‘SVT1’ ChannelNumber = ‘44’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/SVT1.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/SVT1.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/SVT1.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/SVT1.png)’ } ‘2478.honeybee.it’ = @{ ChannelName = ‘NRK1’ ChannelNumber = ‘46’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/NRK1.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/NRK1.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/NRK1.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/NRK1.png)’ }#\> ‘natgeo.dk’ = @{ ChannelName = ‘National Geographic’ ChannelNumber = ‘29’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/National\_Geographic\_Channel.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/National_Geographic_Channel.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/National\_Geographic\_Channel.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/National_Geographic_Channel.png)’ } ‘mtv.dk’ = @{ ChannelName = ‘MTV Danmark’ ChannelNumber = ‘41’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/MTV.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/MTV.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/MTV.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/MTV.png)’ } ‘kanal5.dk’ = @{ ChannelName = ‘Kanal 5’ ChannelNumber = ‘5’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Kanal\_5.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Kanal_5.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Kanal\_5.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Kanal_5.png)’ } ‘kanal4.dk’ = @{ ChannelName = ‘Kanal 4’ ChannelNumber = ‘30’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Kanal\_4.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Kanal_4.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Kanal\_4.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Kanal_4.png)’ } ‘ft.dk’ = @{ ChannelName = ‘Folketinget’ ChannelNumber = ‘48’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Folketinget.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Folketinget.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Folketinget.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Folketinget.png)’ } ‘eurosport.sbstv.dk’ = @{ ChannelName = ‘Eurosport 2’ ChannelNumber = ‘16’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Eurosport\_2.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Eurosport_2.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Eurosport\_2.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Eurosport_2.png)’ } ‘eurosport.dk’ = @{ ChannelName = ‘Eurosport 1’ ChannelNumber = ‘15’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Eurosport\_1.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Eurosport_1.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Eurosport\_1.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Eurosport_1.png)’ } ‘esports.viasat.dk’ = @{ ChannelName = ‘eSportsTV’ ChannelNumber = ‘49’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/esportstv.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/esportstv.png)’ } ‘dr2.dr.dk’ = @{ ChannelName = ‘DR2’ ChannelNumber = ‘8’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/DR2.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/DR2.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/DR2.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/DR2.png)’ } ‘dr1.dr.dk’ = @{ ChannelName = ‘DR1’ ChannelNumber = ‘1’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/DR1.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/DR1.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/DR1.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/DR1.png)’ } ‘6-eren.dk’ = @{ ChannelName = ‘6eren’ ChannelNumber = ‘6’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/6eren.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/6eren.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/6eren.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/6eren.png)’ } ‘golf.viasat.dk’ = @{ ChannelName = ‘Viasat Golf’ ChannelNumber = ‘33’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Viasat\_Golf.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Viasat_Golf.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Viasat\_Golf.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Viasat_Golf.png)’ } ‘investigation.discovery.dk’ = @{ ChannelName = ‘Investigation Discovery’ ChannelNumber = ‘19’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Investigation\_Discovery.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Investigation_Discovery.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Investigation\_Discovery.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Investigation_Discovery.png)’ } ‘discovery.dk’ = @{ ChannelName = ‘Discovery Channel’ ChannelNumber = ‘18’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/Discovery\_Channel.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/Discovery_Channel.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/Discovery\_Channel.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/Discovery_Channel.png)’ } ‘dk4.dk’ = @{ ChannelName = ‘DK4’ ChannelNumber = ‘32’ ChannelIcon = ‘[https://raw.githubusercontent.com/dvidebaek/DK\_Channel\_Logos/master/DK4.png](https://raw.githubusercontent.com/dvidebaek/DK_Channel_Logos/master/DK4.png)’ ProgrammeIcon = ‘[https://raw.githubusercontent.com/dvidebaek/Plex\_Thumbs/master/DK4.png](https://raw.githubusercontent.com/dvidebaek/Plex_Thumbs/master/DK4.png)’ }

}

[XML]$EPG = New-Object System.Xml.XmlDocument

$XMLDeclaration = $EPG.CreateXmlDeclaration(“1.0”,“UTF-8”,$null)

$EPG.AppendChild($XMLDeclaration)

$XMLRootNode = $EPG.CreateNode(“element”,“tv”,$null)

foreach ($Channel in $Channels.Keys) {

```
$ChannelName = ($Channels[$Channel]).ChannelName $ChannelIcon = ($Channels[$Channel]).ChannelIcon $ChannelNumber = ($Channels[$Channel]).ChannelNumber$XMLChannel = $EPG.CreateNode("element","channel",$null) $XMLChannel.SetAttribute("id","$ChannelName") $XMLDisplayName = $EPG.CreateNode("element","display-name",$null) $XMLDisplayName.SetAttribute("lang","da") $XMLDisplayName.InnerText = "$ChannelName" $XMLIcon = $EPG.CreateNode("element","icon",$null) $XMLIcon.SetAttribute("src","$ChannelIcon") $XMLLcn = $EPG.CreateNode("element","lcn",$null) $XMLLcn.InnerText = "$ChannelNumber"

$XMLChannel.AppendChild($XMLDisplayName) $XMLChannel.AppendChild($XMLIcon) $XMLChannel.AppendChild($XMLLcn) $XMLRootNode.AppendChild($XMLChannel)

```

}

$EPG.AppendChild($XMLRootNode)

for ($i = $StartDate; $i -le $EndDate; $i=$i.AddDays(1)) { $Dates = $i.ToString(‘yyyy-MM-dd’)

```
    foreach ($Programmes in $Channels.Keys) {

        $From = [xml](Invoke-RestMethod -Method Get -Uri ("http://xmltv.xmltv.se/$($Programmes)_$($Dates).xml") -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome -ContentType "application/xml")

            foreach ($node in $From.tv.programme) {

                $XMLProgrammeChannel = ($Channels[$node.channel]).ChannelName $node.SetAttribute("channel","$XMLProgrammeChannel") $EPG.tv.AppendChild($EPG.ImportNode($node, $true)) } } }

```

$EPG.Save(‘C:\users\dvide\OneDrive\Desktop\testxml.xml’)
```

I now believe it's not the invoke-restmethod that generates the weird characters. Maybe it's `$EPG.Save('C:\users\dvide\OneDrive\Desktop\testxml.xml')`

I'm lost hope somebody can help me

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [August 21, 2020, 7:29am UTC](https://forums.powershell.org/t/invoke-restmethod-encoding-problem/14823/4 "2020-08-21T07:29:05Z")

</div>

Invoke-RestMethod is just returning at payload from an API. This can be tested by using curl or postman and looking at the XML that is returned. You can save the content directly with Out-File, but it appears you should be concentrating on where exactly the characters appears starting at the source. Another option:

[https://stackoverflow.com/questions/30265973/how-can-i-force-or-specify-encoding-type-using-xml-save](https://stackoverflow.com/questions/30265973/how-can-i-force-or-specify-encoding-type-using-xml-save)

---

<div class="post-metadata">

**Author:** ![dvidebaek](https://avatars.discourse-cdn.com/v4/letter/d/a9a28c/32.png) [@dvidebaek](https://forums.powershell.org/u/dvidebaek)\
**Post date:** [August 23, 2020, 2:36am UTC](https://forums.powershell.org/t/invoke-restmethod-encoding-problem/14823/5 "2020-08-23T02:36:03Z")

</div>

[quote quote=251690]Invoke-RestMethod is just returning at payload from an API. This can be tested by using curl or postman and looking at the XML that is returned. You can save the content directly with Out-File, but it appears you should be concentrating on where exactly the characters appears starting at the source. Another option:

[https://stackoverflow.com/questions/30265973/how-can-i-force-or-specify-encoding-type-using-xml-save](https://stackoverflow.com/questions/30265973/how-can-i-force-or-specify-encoding-type-using-xml-save)

[/quote]

Used -outfile and loaded the xml. That way it worked. The link advised I couldn’t get to work. I’m Running this on PowerShell 7.0.3 by the way.

&nbsp;

[pre] Invoke-RestMethod -Method Get -Uri “[XMLTV | Honeybee.it](http://xmltv.xmltv.se/%24(%24Programmes)_%24(%24Dates).xml)” -ContentType “application/xml” -OutFile “C:\users\dvide\Desktop$($Programmes)-$($Dates).xml”

[xml]$LoadXML = Get-Content -Encoding utf8NoBOM -Path "C:\users\dvide\Desktop\$($Programmes)-$($Dates).xml" [/pre]

Don't know whats going on in PowerShell... Maybe it's a bug?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/invoke-restmethod-encoding-problem/14823/6 "2024-05-16T20:29:01Z")

</div>


