N
N
Nikolai2017-11-01 11:26:31
PowerShell
Nikolai, 2017-11-01 11:26:31

How to fix the problem with displaying comments in Cyrillic when creating a script through SMO Scripting?

Hello,
We use MS SQL Scripting to control changes in procedures, tables, functions in databases on MS SQL servers.
Due to production needs, we store everything in cp1251.

[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null
...
$scriptr = New-Object ('Microsoft.SqlServer.Management.Smo.Scripter')
...
$scriptr.Options.AnsiFile = $True
...

With this setting, all comments and variable values ​​in Cyrillic turn into question marks:
@Brief = 'BOARD', 
@Name = '????? ??????',

How to teach the script to correctly print Cyrillic?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolay, 2017-11-01
@se7en_up

Decision:

...
$scriptr.Options.Encoding = [System.Text.Encoding]::GetEncoding(1251)
...

A
azarij, 2017-11-01
@azarij

$scriptr.Options.Encoding = New-Object ("System.Text.ASCIIEncoding")

and if you play around with different encodings - unicode, utf8, utf16, utf32?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question