본문 바로가기

IT/Internet

[Microsoft Teams] Powershell - ConvertTo-Json UTF8 이슈

Powershell 에서 Teams 로 Webhook 을 보내면 한글이 ??로 표시되는 경우가 있다.

$Params = @{
Uri = 'https://outlook.office.com/webhook/...'
Method = 'Post'
ContentType = 'Application/Json'
#Headers = @{'accept'='application/json'}
Body = $TeamsJSON | ConvertTo-Json -Depth 5
}


# Send It
$Request = Invoke-RestMethod @Params

 

Json 을 UTF8 (BOM 없음) 으로 변환

$TempBody = $TeamsJSON | ConvertTo-Json -Depth 5

# Build the web request
$Params = @{
Uri = 'https://outlook.office.com/webhook/...'
Method = 'Post'
ContentType = 'Application/Json'
#Headers = @{'accept'='application/json'}
Body = [System.Text.Encoding]::UTF8.GetBytes($TempBody)
}


# Send It
$Request = Invoke-RestMethod @Params