Quantcast
Channel: Software Communities : Popular Discussions - ActiveRoles
Viewing all articles
Browse latest Browse all 1277

Compliance Reporting and Umlauts

$
0
0

Hi seems I can't post a blog so a discussion will have to do ....

 

I'm writing some compliance reports and scheduling them with ARS - the reports are basically group memberships and the are text files with .csv extentions.  The problem I had was that the umlauts were being mangled by Excel when the auditors open the files.

 

The fix......

 

It appears that streamwriter defaults to UTF8 which preserves the umlauts (opening in notepad correctly identified the file as UTF8) but it appears the BOM was not being written to the file so Excel was not correctly formatting the file.

 

 

To fix this I had to explicity force the streamwriter to write the BOM. 

Create a system.text.UTF8Encoding object

 

$utf8 = New-Object System.Text.UTF8Encoding($true)

 

Using $false would stop the BOM being written – you might want that option but it seems streamwritter does that by default anyway

 

Then when you open the file use the object as follows to force the BOM being written to the file

 

$reportFile = new-object system.IO.StreamWriter($filename,$true,$utf8)

 

you write to the file using $reportfile.writeline("Text you want added - or the ad object.attribute for example")

 

Why do I use the streamwriter instead of export-csv ?

1. its quicker (http://blogs.technet.com/b/gbordier/archive/2009/05/05/powershell-and-writing-files-how-fast-can-you-write-to-a-file.aspx)

2. export-csv does not format the file correctly as there are commas in the user names

3. export-csv has the same problem writing to the file and if you use the -encoding switch then you get a single line in quotes so no good for an excel spreadsheet

4. were getting away from teh point of the post which is just to tell you how to do it using streamwriter - if thats what you wanted to do

 

Lee Andrews


Viewing all articles
Browse latest Browse all 1277

Trending Articles