About

MS MVP Logo

View Marc Lognoul [MVP]'s profile on LinkedIn

Disclaimer

The information and materials in this site are provided "AS IS" with no warranties, and confering no rights. This site does not represent the thoughts, intentions, plans or strategies of our employers, customers, friends or family, solely our own personal opinions.

Now in Native x64: Reading an Excel sheet using PowerShell and ADO.Net

by Marc 19. July 2010 09:49

Long ago I blogged about using PowerShell to read out an XLS(X) file using ADO.Net. Until recently, only the x86 version of the ODBC driver was available.

Fortunately, Microsoft recently release a x64 version of the drivers as part of the Microsoft Access Database Engine 2010 Redistributable Package. Download link:

Interestingly, while this package is labeled “Office 2010”, the provider's names references “Office 12” (2007) –> this should have be released earlier :)

Marc

Tags:

PowerShell | Scripting and Automation | Office

A Bunch of issues with Windows Vista and SharePoint’s Explorer View

by Marc 31. March 2010 15:35

It’s critical to keep systems up-to-date with patches, the 4 issues described hereunder prove it again ;) They affect Windows Vista only, not 7 or XP. Certainly because the WebClient went through a serious revamp with Vista, Seven drawing benefit from product maturation.

Explorer View does not work when connection goes through a forward proxy asking for authentication 

When browsing a SharePoint site through a forward proxy (or simply web proxy) server requiring authentication, everything is working fine but when switching to Explorer viewing or simply trying to open an MS Office document, whether you directly get an “Access Denied” message or you get prompted multiple times for authentication (pop-up windows).

This problem occurs because early Vista’s implementation of the WebDAV redirector (aka WebClient) used by the Explorer do not handle correctly the HTTP Response 407 (Proxy Authentication Required)

Solution: install this hot fix (http://support.microsoft.com/kb/954807) or install Vista Service Pack 2. note: the hot fix requires SP1 to be present

Explorer View does not automatically forward credentials if the site does not belong to Local Intranet zone

A tricky one: let’s say that a user is browsing a SharePoint site that belongs to the Trusted Sites security zone of Internet Explorer while the browser is configured to automatically forward credentials for that zone (non-standard config). Although it will work fine with the browser, it will miserably fail with the Explorer View because on vista, WebClient does not rely on Internet Explorer security zones configuration and therefore does not automatically forward credentials under some circumstances.

Solution: Install this hot fix (http://support.microsoft.com/kb/943280) or install Vista Service Pack 2 and configure registry as described in the MS KB article related to the hot fix (this step is mandatory).

Explorer View does not automatically forward credentials if IE’s proxy setting check box “Automatically detect settings” is cleared

Pretty much derived from the previous issue, this one will behave identically.

Solution: install this hot fix (http://support.microsoft.com/kb/941853) or install Vista Service Pack 2

 

Explorer View might merge merge cookies leading to authentication issues (or other issues as well)

Cookies are often used to maintained state and sometimes to allow some kind of authentication mechanism, like form-based authentication.

In the case of authentication, products such as ISA/IAG/TMG may use so called “persistent” cookies to allow application to share authentication. This is typical when you want to seamlessly switch from a browser to an MS Office application when working with SharePoint.

Apparently, Vista’s implementation of the WebClient may accidently merge cookies when passing them to the web server or gateway, making them unusable.

Solution: install this Internet Explorer Cumulative Security Update (http://support.microsoft.com/kb/972260/), which also includes functional updates solving that problem…

Credits go to Pascal B and Nicolas S both MSFT for this one. Thanks guys!

 

Marc

Tags:

IIS | Office | SharePoint | Troubleshooting

Repost : Reading an Excel sheet using PowerShell and ADO.Net

by Marc 16. August 2008 19:32

Nothing new here, just a repost by popular demand... 
Many examples on the Internet show how to use the Office Automation COM object to achieve this. But under some circumstances, this is not possible because Excel is simply not installed locally.


Lets instantiate the objects we need:
$OleDbConn = New-Object "System.Data.OleDb.OleDbConnection"
$OleDbCmd = New-Object "System.Data.OleDb.OleDbCommand"
$OleDbAdapter = New-Object "System.Data.OleDb.OleDbDataAdapter"
$DataTable = New-Object "System.Data.DataTable"


Set the connection string and connect. Please pay attention to the syntax, otherwise, you’ll get cryptic errors such as “Could not find installable ISAM”. Also, the file should not be locked exclusively
$OleDbConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\lognoulm\Desktop\servercfg.xls;Extended Properties=""Excel 8.0;HDR=YES"""
$OleDbConn.Open()


Optionally, to check that the connection is open, display the “State” property:
$OleDbConn.State


Now let’s construct a SQL query. Syntax for Excel is a little special, look at the end of this post for external references.
$OleDbCmd.Connection = $OleDbConn
$OleDbCmd.CommandText = "SELECT * FROM [Sheet1$]"


Then set the Adapter object
$OleDbAdapter.SelectCommand = $OleDbCmd


And then fill the DataTable object with the results
$OleDbAdapter.Fill($DataTable)


If everything went fine, the command above will return the number of row present is the DataTable object. To display the “raw” contents, just enter
$DataTable


To show the first line (aka Row), use this $DataTable.Rows[0]
And how to display a given field in that row? Just use the field header. In my XLS, one header is for example “Name”
$DataTable.Rows[0].Name

More information can be found here:

Note: This was not tested using an XLSX files but with a standard XLS instead
Note 2: DataSet can be used instead of DataTable object but I prefer this one in favor of greater simplicity (this is to be used by sysadmins, not developersJ)
Note 3: I blogged about reading but you can update and insert too, see references above for details

And cut!

Tags:

PowerShell | Office