Powershell – Export to EXCEL issue

I was trying to use some simple script to create a workbook in Excel 2007 and add some worksheets in it, with data.

Spend hours on it, but it just opened up the Excel application. But no workbook and no sheets ? Crying face

This was the intial code :

#[threading.thread]::CurrentThread.CurrentCulture = 'en-US'
$Excel = new-Object -com Excel.Application
$Excel.visible = $True
$Excel.DisplayAlerts = $False
$ExcelWB = $Excel.Workbooks.Add()

# adding 3 extra sheets
$Sheet = $ExcelWB.Worksheets.Add()
$Sheet = $ExcelWB.Worksheets.Add()
$Sheet = $ExcelWB.Worksheets.Add()

# Assign each worksheet to a variable and
# name the worksheet.
$Sheet1 = $ExcelWB.Worksheets.Item(1)
$Sheet2 = $ExcelWB.WorkSheets.Item(2)
$Sheet3 = $ExcelWB.WorkSheets.Item(3)
$Sheet4 = $ExcelWB.WorkSheets.Item(4)
$Sheet5 = $ExcelWB.WorkSheets.Item(5)
$Sheet6 = $ExcelWB.WorkSheets.Item(6)
$Sheet1.Name = "General"
$Sheet2.Name = "System"
$Sheet3.Name = "Processor"
$Sheet4.Name = "Memory"
$Sheet5.Name = "Disk"
$Sheet6.Name = "Network"
Sleep 2
write-host $Error[0]
Sleep 2


On the second line you can notice the line including

[threading.thread]::CurrentThread.CurrentCulture = 'en-US'

When you uncomment it, everything works fine ?

Reason is that I use an English OS with a non English regional settings, which seems to be the issue.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: