Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Text with special characters or Encoding

Reply
 
Old 06-09-2008   #1 (permalink)
Eivind Brenningen


 
 

Text with special characters or Encoding

Hi,

I'm having trouble with scripts which parses text from a file where the text
contains special characters (norwegian/scandinavian). Any tips on how to make
sure PS reads these correctly?

-Eivind Brenningen
Senior IT Consultant

My System SpecsSystem Spec
Old 06-09-2008   #2 (permalink)
Eivind Brenningen


 
 

Re: Text with special characters or Encoding

Hi, and thanks!

Unfortunately this didn't change anything.

I'm trying to manipulate AD user objects, but usernames with norwegian
characters always have these replaced by other characters (ie. ø (oe) is
replaced by ?). The input is read from a csv-file.

--
-Eivind Brenningen
Senior IT Consultant


"Shay Levi" wrote:
Quote:

>
>
> Hi Eivind,
>
> I found three culture names for Norwegian, so choose which one to use:
>
> PS 5> $cultures = [System.Globalization.CultureInfo]::GetCultures("AllCultures")
> PS 6> $cultures| where {$_.DisplayName -match "norwe"} | select Name,DisplayName
>
>
> Name DisplayName
> ---- -----------
> no Norwegian
> nb-NO Norwegian, Bokm?l (Norway)
> nn-NO Norwegian, Nynorsk (Norway)
>
>
>
>
> This is the script, comments inline:
>
>
> $newCulture = "nn-NO"
> $scriptBlock = { ... put your code here ... }
>
> # get the original culture
> $orgCulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture
>
> # apply new culture
> [System.Threading.Thread]::CurrentThread.CurrentUICulture = $newCulture
> [System.Threading.Thread]::CurrentThread.CurrentCulture = $newCulture
>
> # execute scriptblock code
> & $scriptBlock
>
> # restore original culture
> [System.Threading.Thread]::CurrentThread.CurrentUICulture = $orgCulture
> [System.Threading.Thread]::CurrentThread.CurrentCulture = $orgCulture
>
>
>
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > Hi,
> >
> > I'm having trouble with scripts which parses text from a file where
> > the text contains special characters (norwegian/scandinavian). Any
> > tips on how to make sure PS reads these correctly?
> >
> > -Eivind Brenningen
> > Senior IT Consultant
>
>
>
My System SpecsSystem Spec
Old 06-09-2008   #3 (permalink)
Shay Levi


 
 

Re: Text with special characters or Encoding



Hi Eivind,

I found three culture names for Norwegian, so choose which one to use:

PS 5> $cultures = [System.Globalization.CultureInfo]::GetCultures("AllCultures")
PS 6> $cultures| where {$_.DisplayName -match "norwe"} | select Name,DisplayName


Name DisplayName
---- -----------
no Norwegian
nb-NO Norwegian, Bokm?l (Norway)
nn-NO Norwegian, Nynorsk (Norway)




This is the script, comments inline:


$newCulture = "nn-NO"
$scriptBlock = { ... put your code here ... }

# get the original culture
$orgCulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture

# apply new culture
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $newCulture
[System.Threading.Thread]::CurrentThread.CurrentCulture = $newCulture

# execute scriptblock code
& $scriptBlock

# restore original culture
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $orgCulture
[System.Threading.Thread]::CurrentThread.CurrentCulture = $orgCulture




---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hi,
>
> I'm having trouble with scripts which parses text from a file where
> the text contains special characters (norwegian/scandinavian). Any
> tips on how to make sure PS reads these correctly?
>
> -Eivind Brenningen
> Senior IT Consultant

My System SpecsSystem Spec
Old 06-09-2008   #4 (permalink)
Shay Levi


 
 

Re: Text with special characters or Encoding



What version of PowerShell do you use? CTP2 can handle 'culture-aware' CSV
files.



---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hi, and thanks!
>
> Unfortunately this didn't change anything.
>
> I'm trying to manipulate AD user objects, but usernames with norwegian
> characters always have these replaced by other characters (ie. ? (oe)
> is replaced by ?). The input is read from a csv-file.
>
> "Shay Levi" wrote:
>
Quote:

>> Hi Eivind,
>>
>> I found three culture names for Norwegian, so choose which one to
>> use:
>>
>> PS 5> $cultures =
>> [System.Globalization.CultureInfo]::GetCultures("AllCultures") PS 6>
>> $cultures| where {$_.DisplayName -match "norwe"} | select
>> Name,DisplayName
>>
>> Name DisplayName
>> ---- -----------
>> no Norwegian
>> nb-NO Norwegian, Bokm?l (Norway)
>> nn-NO Norwegian, Nynorsk (Norway)
>> This is the script, comments inline:
>>
>> $newCulture = "nn-NO"
>> $scriptBlock = { ... put your code here ... }
>> # get the original culture
>> $orgCulture =
>> [System.Threading.Thread]::CurrentThread.CurrentUICulture
>> # apply new culture
>> [System.Threading.Thread]::CurrentThread.CurrentUICulture =
>> $newCulture [System.Threading.Thread]::CurrentThread.CurrentCulture =
>> $newCulture
>>
>> # execute scriptblock code
>> & $scriptBlock
>> # restore original culture
>> [System.Threading.Thread]::CurrentThread.CurrentUICulture =
>> $orgCulture [System.Threading.Thread]::CurrentThread.CurrentCulture =
>> $orgCulture
>>
>> ---
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> Hi,
>>>
>>> I'm having trouble with scripts which parses text from a file where
>>> the text contains special characters (norwegian/scandinavian). Any
>>> tips on how to make sure PS reads these correctly?
>>>
>>> -Eivind Brenningen
>>> Senior IT Consultant

My System SpecsSystem Spec
Old 06-09-2008   #5 (permalink)
Kiron


 
 

Re: Text with special characters or Encoding

Create a copy of the original CSV with Unicode or UTF8 encoding and test it.

sc .\copy.csv (gc .\original.csv) -en unicode

# test it
ipcsv .\copy.csv

--
Kiron
My System SpecsSystem Spec
Old 06-09-2008   #6 (permalink)
Shay Levi


 
 

Re: Text with special characters or Encoding


Is powershell running under the norwegian/scandinavian regional settings?


---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> What version of PowerShell do you use? CTP2 can handle 'culture-aware'
> CSV files.
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> Hi, and thanks!
>>
>> Unfortunately this didn't change anything.
>>
>> I'm trying to manipulate AD user objects, but usernames with
>> norwegian characters always have these replaced by other characters
>> (ie. ? (oe) is replaced by ?). The input is read from a csv-file.
>>
>> "Shay Levi" wrote:
>>
Quote:

>>> Hi Eivind,
>>>
>>> I found three culture names for Norwegian, so choose which one to
>>> use:
>>>
>>> PS 5> $cultures =
>>> [System.Globalization.CultureInfo]::GetCultures("AllCultures") PS 6>
>>> $cultures| where {$_.DisplayName -match "norwe"} | select
>>> Name,DisplayName
>>>
>>> Name DisplayName
>>> ---- -----------
>>> no Norwegian
>>> nb-NO Norwegian, Bokm?l (Norway)
>>> nn-NO Norwegian, Nynorsk (Norway)
>>> This is the script, comments inline:
>>> $newCulture = "nn-NO"
>>> $scriptBlock = { ... put your code here ... }
>>> # get the original culture
>>> $orgCulture =
>>> [System.Threading.Thread]::CurrentThread.CurrentUICulture
>>> # apply new culture
>>> [System.Threading.Thread]::CurrentThread.CurrentUICulture =
>>> $newCulture [System.Threading.Thread]::CurrentThread.CurrentCulture
>>> =
>>> $newCulture
>>> # execute scriptblock code
>>> & $scriptBlock
>>> # restore original culture
>>> [System.Threading.Thread]::CurrentThread.CurrentUICulture =
>>> $orgCulture [System.Threading.Thread]::CurrentThread.CurrentCulture
>>> =
>>> $orgCulture
>>> ---
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> Hi,
>>>>
>>>> I'm having trouble with scripts which parses text from a file where
>>>> the text contains special characters (norwegian/scandinavian). Any
>>>> tips on how to make sure PS reads these correctly?
>>>>
>>>> -Eivind Brenningen
>>>> Senior IT Consultant

My System SpecsSystem Spec
Old 06-10-2008   #7 (permalink)
Eivind Brenningen


 
 

Re: Text with special characters or Encoding

That did the trick!

Thank you both.
--
-Eivind Brenningen
Senior IT Consultant


"Kiron" wrote:
Quote:

> Create a copy of the original CSV with Unicode or UTF8 encoding and test
> it.
>
> sc .\copy.csv (gc .\original.csv) -en unicode
>
> # test it
> ipcsv .\copy.csv
>
> --
> Kiron
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Using special characters on my tagline Live Messenger
Password with special characters Live Mail
Typing in special characters bug Vista General
Special Characters - how? Vista General
How to run program with special characters PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46