update warning msg for Read-OleDbData

This commit is contained in:
Roy Ashbrook
2021-11-09 09:05:15 -05:00
parent 7177623104
commit 4fa6fbda01

View File

@@ -36,28 +36,15 @@ function Read-OleDbData {
[String] $SqlStatement
)
if ($IsLinux -or $IsMacOS) {
#todo: possibly add support for linux/mac somehow. i haven't researched this at all as i
# don't have a need for that and i'm not sure anyone else would in this context, but it does
# appear that once upon a time mono had support for oledb, so maybe it is (or was) supported.
# mono link here: https://www.mono-project.com/archived/ole_db/
Write-Error "Read-OleDbData only runs on Windows"
try {
if ((New-Object system.data.oledb.oledbenumerator).GetElements().SOURCES_NAME -notcontains "Microsoft.ACE.OLEDB.12.0") {
Write-Warning "Microsoft.ACE.OLEDB.12.0 provider is missing! You will not be able to query Excel files without it. Please install from https://www.microsoft.com/en-us/download/details.aspx?id=54920"
}
}
catch {
Write-Error "System.Data.OleDb is not working or you are on an unsupported platform."
return
}
#todo: add checks for dotnet libs
#todo: possibly add checks for ace drivers, but maybe only needed if we want to restrict usage.
# i currently just pass through the query and connection string so user is only limited by
# their own machine setup, but they have to check for those dependencies themselves.
#todo: possibly try/catch. i personally do not do this, as i let them throw naturally and catch
# them/handle them outside of this function.
#todo: possibly allow for DataSets instead of just DataTable. I used to use a similar method before
# switching to the sqlcmd module and use datasets as I had multiple tables coming back from
# sql sometimes. i think in this case, it's best to just keep it simple, but maybe someone
# out there would prefer to be able to get multiple tables back. i have not tested that
# with the OleDbDataAdapter.
#todo: possibly just return the datatable, i do it as below because i prefer to simplify the output
# and get rid of the extra fields that come back with the datatable or rows.
$DataTable = new-object System.Data.DataTable
$DataAdapter = new-object System.Data.OleDb.OleDbDataAdapter $SqlStatement, $ConnectionString