Last active
October 4, 2017 22:21
-
-
Save jeffpatton1971/423f8ecdb1c448133bf3334db6e4fc62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param | |
( | |
$strFileName = "C:scriptsfile.xlsx", | |
$strSheetName = 'Out' | |
) | |
if (!(($strSheetName.Substring($strSheetName.Length-1,1)) -eq '$')) | |
{ | |
$strSheetName = "$($strSheetName)`$" | |
} | |
$strProvider = "Provider=Microsoft.ACE.OLEDB.12.0" | |
$strDataSource = "Data Source = $strFileName" | |
$strExtend = "Extended Properties=`"Excel 12.0 Xml;HDR=YES;IMEX=1`"" | |
$strQuery = "Select * from [$strSheetName]" | |
$objConn = New-Object System.Data.OleDb.OleDbConnection("$strProvider;$strDataSource;$strExtend") | |
$sqlCommand = New-Object System.Data.OleDb.OleDbCommand($strQuery) | |
$sqlCommand.Connection = $objConn | |
$objConn.open() | |
$DataReader = $sqlCommand.ExecuteReader() | |
While($DataReader.read()) | |
{ | |
$data = $DataReader[0].Tostring() | |
write-host $data | |
} | |
$dataReader.close() | |
$objConn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment