{"id":14041,"date":"2011-05-04T00:01:00","date_gmt":"2011-05-04T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/05\/04\/use-ace-drivers-and-powershell-to-talk-to-access-and-excel\/"},"modified":"2011-05-04T00:01:00","modified_gmt":"2011-05-04T00:01:00","slug":"use-ace-drivers-and-powershell-to-talk-to-access-and-excel","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-ace-drivers-and-powershell-to-talk-to-access-and-excel\/","title":{"rendered":"Use ACE Drivers and PowerShell to Talk to Access and Excel"},"content":{"rendered":"<p><b>Summary<\/b>: Quit using deprecated JET drivers to talk to Microsoft Access and Excel. Learn how to use Windows PowerShell and ACE Drivers.<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/>&nbsp; Hey, Scripting Guy! How do I get data out of Microsoft Access and Excel files and into SQL Server by using Windows PowerShell?<\/p>\n<p>&mdash;MC<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/> Hello MC, Microsoft Scripting Guy, Ed Wilson, is here. We are at the center of SQL Week in honor of <a target=\"_blank\" href=\"http:\/\/sqlrally.com\">SQLRally<\/a> next week, and our guest blogger today is Chad Miller. <\/p>\n<p style=\"padding-left: 30px\">Chad Miller (<a target=\"_blank\" href=\"http:\/\/sev17.com\/\">Blog<\/a>|<a target=\"_blank\" href=\"http:\/\/www.twitter.com\/cmille19\">Twitter<\/a>) is a SQL Server DBA and the senior manager of database administration at Raymond James Financial. In his spare time, he is the project coordinator and developer of the CodePlex project SQL Server PowerShell Extensions (<a target=\"_blank\" href=\"http:\/\/sqlpsx.codeplex.com\/\">SQLPSX<\/a>). Chad leads the <a target=\"_blank\" href=\"http:\/\/powershellgroup.org\/tampa.fl\">Tampa Powershell User Group<\/a> and is a frequent speaker at IT Camps, SQL Saturdays, and Code Camps.<\/p>\n<p>Microsoft Access and Excel have been called the desktop database, and companies have a lot of data stored in them. It is inventible that you will need to load some of these files into a SQL Server database. <\/p>\n<p><b>Note<\/b>: There are a variety of tools provided by Microsoft to assist in migrating your data into a SQL Server database. In addition Windows Azure, Microsoft Access Services, and Microsoft Excel Services for SharePoint provide alternative solutions, which should be considered as possible strategies. Other solutions may be better suited than the Windows PowerShell scripts demonstrated in this blog post.<\/p>\n<h3><b>Connectivity<\/b><\/h3>\n<p>Connectivity to a data source is accomplished through ODBC drivers or OLE DB Providers. When we connect to a data source, we first need to determine which connectivity components to use. A Windows operating system includes the ODBC driver and OLE DB Providers for connecting to a variety of data sources, including SQL Server. However, newer Microsoft Office connectivity components are not included with the operating system. Instead, Microsoft Office connectivity components are installed with Microsoft Office or alternatively through something called the Access Control Entry (ACE) driver. <\/p>\n<p>One of the cool things about ACE is first, its name. But more importantly, ACE is completely free, and it even includes a 64-bit version. <\/p>\n<p><b>Important<\/b>: ensure that you have the ACE driver\/provider installed on your machine or else the Windows PowerShell scripts demonstrated in this post will not work! Before you proceed, go to <a target=\"_blank\" href=\"http:\/\/www.microsoft.com\/downloads\/en\/details.aspx?FamilyID=c06b8369-60dd-4b64-a44b-84b371ede16d&amp;displaylang=en\">Microsoft Access Database Engine 2010 Redistributable<\/a>, and download AccessDatabaseEngine.exe or AccessDatabaseEngine_x64.exe, depending on your operating system. The ACE drivers are supported by Windows 7; Windows Server 2003 R2, 32-bit x86; Windows Server 2003 R2, x64 editions; Windows Server 2008 R2; Windows Server 2008 with Service Pack 2; Windows Vista with Service Pack 1; and Windows XP with Service Pack 3.<\/p>\n<p>When you you have ACE drivers, there is no reason to use the old deprecated JET drivers&mdash;even for older versions of Microsoft Access and Excel. A common mistake I see, even with seasoned developers, is to drop to JET for .mdb and .xls files when you don&rsquo;t need to. I have made this mistake myself past.<\/p>\n<p>I found <a target=\"_blank\" href=\"http:\/\/blogs.msdn.com\/b\/psssql\/archive\/2010\/01\/21\/how-to-get-a-x64-version-of-jet.aspx\">a helpful blog post on MSDN<\/a> from the CSS SQL Server Engineers that talks about different data providers and discusses a migration strategy. <\/p>\n<h3><b>Installing the ACE Module<\/b><\/h3>\n<p>Having addressed the issue of connectivity, we can now look at a simple Windows PowerShell module that provides a function over the ACE driver, which I call ACE. <\/p>\n<p>To install the ACE module, perform the following steps. <\/p>\n<ol>\n<li>Create a folder named ACE under Documents\\WindowsPowerShell\\Modules.<\/li>\n<li>Save the <a target=\"_blank\" href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/af687d99-5611-4097-97e4-691fda84ad42\">ACE script from the Scripting Guys Script Repository<\/a> as ACE.psm1 in your Documents\\WindowsPowerShell\\Modules\\ACE folder. This is shown in the following image. <\/li>\n<\/ol>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4174.ACEModule_2C76161B.png\"><img decoding=\"async\" height=\"164\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7120.ACEModule_thumb_0FF9243B.png\" alt=\"Image of folder\" border=\"0\" title=\"Image of folder\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><span style=\"text-decoration: underline\">&nbsp;<\/span><\/p>\n<p>To use the module, you need to import the module into your current Windows PowerShell session. This is accomplished by running the following command.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Import-module ace<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>The ace module consists of one exported function called <b>Get-ACEData<\/b>. To see Help including examples of usage, run the following command.<\/p>\n<blockquote>\n<p><span style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Help Get-ACEData &ndash;full<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<h3><b>Using the ACE Module<\/b><\/h3>\n<p>Now that the ACE module is installed and ready to use, let us look at couple of examples.<\/p>\n<h4><b>Getting Excel Data<\/b><\/h4>\n<p>I am going to use an Excel file called backup.xlsx as shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3823.ExcelDemo_4FC30AC0.png\"><img decoding=\"async\" height=\"549\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8228.ExcelDemo_thumb_0F8CF146.png\" alt=\"Image of Excel file\" border=\"0\" title=\"Image of Excel file\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<p>First, let us list the worksheets that are part of the backup.xlsx spreadsheet.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">PS C:\\Users\\u00\\bin&gt; Get-ACEData -FilePath .\\backupset.xlsx -TableListOnly<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_CATALOG : <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_SCHEMA<span>&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_NAME<span>&nbsp;&nbsp;&nbsp; <\/span>: Sheet1$<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_TYPE<span>&nbsp;&nbsp;&nbsp; <\/span>: TABLE<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_GUID<span>&nbsp;&nbsp;&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">DESCRIPTION<span>&nbsp;&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_PROPID<span>&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">DATE_CREATED<span>&nbsp; <\/span>: 4\/19\/2011 9:41:11 PM<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">DATE_MODIFIED : 4\/19\/2011 9:41:11 PM<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_CATALOG : <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_SCHEMA<span>&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_NAME<span>&nbsp;&nbsp;&nbsp; <\/span>: Sheet2$<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_TYPE<span>&nbsp;&nbsp;&nbsp; <\/span>: TABLE<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_GUID<span>&nbsp;&nbsp;&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">DESCRIPTION<span>&nbsp;&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_PROPID<span>&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">DATE_CREATED<span>&nbsp; <\/span>: 4\/19\/2011 9:41:11 PM<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">DATE_MODIFIED : 4\/19\/2011 9:41:11 PM<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_CATALOG : <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_SCHEMA<span>&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TABLE_NAME<span>&nbsp;&nbsp;&nbsp; <\/span>: Sheet3$<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">&hellip;<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>To shorten the output, I will pipe the results to <b>Select-Object<\/b> and specify the TABLE_NAME property only.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">PS C:\\Users\\u00\\bin&gt; Get-ACEData -FilePath .\\backupset.xlsx -TableListOnly | Select-Object TABLE_NAME<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span>TABLE_NAME<\/span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span>&#8212;&#8212;&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span>Sheet1$<\/span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span>Sheet2$<\/span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"color: #000000\"><span style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span>Sheet3$ <\/span><\/span><\/span><span style=\"line-height: normal;list-style-type: disc\"><span><span style=\"font-family: Calibri\"><span>&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/span><\/p><\/blockquote>\n<p>We can see that the three worksheets that make up the spreadsheet are returned. Next, let us return the data. To return all data from every worksheet, run the following command.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds= Get-ACEData -FilePath .\\backupset.xlsx<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>If we look at the <b>$ds<\/b> variable through <b>Get-Member<\/b>, we see that the function returns the DataSet shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5670.dataset_5609E14E.png\"><img decoding=\"async\" height=\"242\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7144.dataset_thumb_2AC54A47.png\" alt=\"Image of command output\" border=\"0\" title=\"Image of command output\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<p>This DataSet is made up of a collection of DataTables. To see how many DataTables, run the following command.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds.Tables.count<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">3<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>To see the DataTable names, run the following command. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds.Tables | Select TableName<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">TableName<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">&#8212;&#8212;&#8212;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Sheet1$<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Sheet2$<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Sheet3$<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>If we want look at the data, we would run:<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds.Tables<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>To see only the first DataTable, specify the collection index or the name of the DataTable, for example:<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds.Tables[0] or $ds.Tables[&ldquo;Sheet1$&rdquo;]<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>If you want to return only the first and second worksheets, we can specify either the <b>Table<\/b> or the <b>Query<\/b> parameter as shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds= Get-ACEData -FilePath .\\backupset.xlsx -Table &#8216;Sheet1$&#8217;,&#8217;Sheet2$&#8217;<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>To restrict the rows that are returned from a worksheet, use the <b>Query<\/b> parameter as shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds = Get-ACEData -FilePath .\\backupset.xlsx -Query &#8220;Select * FROM [Sheet1$] WHERE [dbname] = &#8216;db1&#8242;&#8221;<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>The ACE driver supports .xls (Excel 2003) and . xlsx (Excel 2007 and higher) files. <\/p>\n<p>Next, we will query a Microsoft Access file.<\/p>\n<h3><b>Getting Access Data<\/b><\/h3>\n<p>I am going to use the sample Northwind Microsoft Access database, which is available from File&gt;&gt;New&gt;&gt;Sample Templates as shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3438.Nortwind_038B0112.png\"><img decoding=\"async\" height=\"349\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0207.Nortwind_thumb_1BAE6B6D.png\" alt=\"Image of template\" border=\"0\" title=\"Image of template\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<p>Just as I did with the Excel file, we will get a list of tables. However, Microsoft Access has different table types, including views and system tables, which we&rsquo;ll need to filter out and load into a variable as shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$tables = Get-ACEData -FilePath .\\Northwind.accdb -TableListOnly | where {$_.TABLE_TYPE -eq &#8216;TABLE&#8217; } | Select -ExpandProperty&nbsp;TABLE_NAME<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$tables<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Customers<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Employee Privileges<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Employees<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Inventory Transaction Types<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Inventory Transactions<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Invoices<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Order Details<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Order Details Status<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Orders<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Orders Status<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Orders Tax Status<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Privileges<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Products<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Purchase Order Details<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Purchase Order Status<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Purchase Orders<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Sales Reports<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Shippers<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Strings<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Suppliers<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>To load all of the regular tables contained in the Northwind Microsoft Access file, run the following command.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds = Get-ACEData -FilePath .\\Northwind.accdb -Table $tables<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>To see the number of tables in the DataSet, run:<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds.Tables.Count<\/span><\/span><\/span><\/p>\n<p><span style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">20<\/span><\/span><\/span><\/p><\/blockquote>\n<p>Like in the Excel example, we can specify queries by using the <b>Query<\/b> parameter or specific tables with the <b>Table<\/b> parameter. The ACE Driver supports .mdb (Access 2003) and .accdb (Access 2007 or higher) formats.<\/p>\n<h3><b>Importing Microsoft Office Data<\/b><\/h3>\n<p>At this point, we have retrieved data from Excel and Access files. Next we will look at loading this data into a SQL Server database. I am going to use the free, SQL Server Express version. If you do not have a SQL Server instance available, you can <a target=\"_blank\" href=\"http:\/\/www.microsoft.com\/express\/Database\/\">download and install SQL Server Express<\/a>. I am also going create a database called <b>hsgb<\/b> in SQL Server Management Studio as shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3835.SSMS_5459157A.png\"><img decoding=\"async\" height=\"366\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5584.SSMS_thumb_4D39D902.png\" alt=\"Image of folder\" border=\"0\" title=\"Image of folder\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<h3><b>Setup<\/b><\/h3>\n<p>In a previous Hey! Scripting Guy blog titled <a target=\"_blank\" href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/11\/01\/use-powershell-to-collect-server-data-and-write-to-sql.aspx\">Use PowerShell to Collect Server Data and Write to SQL<\/a>, I demonstrated three functions that I will use to load and query the data in SQL Server. Download each script from the following locations:<\/p>\n<ul>\n<li><a target=\"_blank\" href=\"http:\/\/gallery.technet.microsoft.com\/ScriptCenter\/en-us\/7985b7ef-ed89-4dfd-b02a-433cc4e30894\">Invoke-SqlCmd2<\/a><\/li>\n<li><a target=\"_blank\" href=\"http:\/\/gallery.technet.microsoft.com\/ScriptCenter\/en-us\/2fdeaf8d-b164-411c-9483-99413d6053ae\">Write-DataTable<\/a><\/li>\n<li><a target=\"_blank\" href=\"http:\/\/gallery.technet.microsoft.com\/ScriptCenter\/en-us\/c193ed1a-9152-4bda-b5c0-acd044e68b2c\">Add-SqlTable<\/a><\/li>\n<\/ul>\n<p>Next, source each function in Windows PowerShell as follows (note that this is dot space dot forward slash).<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">. .\/Invoke-SqlCmd2<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">. .\/Write-DataTable<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">. .\/Add-SqlTable<\/span><\/span><\/span><span style=\"line-height: 12pt\"><\/span><\/p>\n<\/blockquote>\n<h3><b>Running Data Imports<\/b><\/h3>\n<p>We are ready to import our Excel and Access data.<\/p>\n<p>To import our Excel data, run the following command.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds= Get-ACEData -FilePath .\\backupset.xlsx -Table &#8216;Sheet1$&#8217;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Add-SqlTable -ServerInstance &#8220;Z003\\SQLEXPRESS&#8221; -Database hsgb -TableName $($ds.Tables[0].TableName) -DataTable $ds.Tables[0]<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Write-DataTable -ServerInstance &#8220;Z003\\SQLEXPRESS&#8221; -Database hsgb -TableName $($ds.Tables[0].TableName) -Data $ds.Tables[0]<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>By running <b>Invoke-SqlCmd2<\/b>, we can see our newly inserted data as shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Invoke-Sqlcmd2 -ServerInstance &#8220;Z003\\SQLEXPRESS&#8221; -Database hsgb -Query &#8220;select * from [sheet1$]&#8221; | Out-GridView<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5504.ExcelOgv_48C3583B.png\"><img decoding=\"async\" height=\"412\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4812.ExcelOgv_thumb_4C617318.png\" alt=\"Image of command output\" border=\"0\" title=\"Image of command output\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<p>To import a group of Microsoft Access tables, run the following command.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds = Get-ACEData -FilePath .\\Northwind.accdb -Table Customers,Suppliers<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds.Tables | foreach {Add-SqlTable -ServerInstance &#8220;Z003\\SQLEXPRESS&#8221; -Database hsgb -TableName $($_.TableName) -DataTable $_ }<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$ds.Tables | foreach {Write-DataTable -ServerInstance &#8220;Z003\\SQLEXPRESS&#8221; -Database hsgb -TableName $($_.TableName) -Data $_<span>&nbsp; <\/span>}<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>By running <b>Invoke-SqlCmd2<\/b>, we can view the data in our new SQL Server tables as shown in the following examples.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Invoke-Sqlcmd2 -ServerInstance &#8220;Z003\\SQLEXPRESS&#8221; -Database hsgb -Query &#8220;select * from customers&#8221; | Out-GridView<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1781.customers_60E6C296.png\"><img decoding=\"async\" height=\"306\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1374.customers_thumb_0BBF26A9.png\" alt=\"Image of table\" border=\"0\" title=\"Image of table\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 11pt;list-style-type: disc;margin: 0in 0in 10pt\"><span style=\"line-height: 12pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">Invoke-Sqlcmd2 -ServerInstance &#8220;Z003\\SQLEXPRESS&#8221; -Database hsgb -Query &#8220;select * from suppliers&#8221; | Out-GridView<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4011.suppliers_1272302C.png\"><img decoding=\"async\" height=\"362\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8228.suppliers_thumb_0B52F3B4.png\" alt=\"Image of table\" border=\"0\" title=\"Image of table\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<p>This blog demonstrated how to query and load the Microsoft Excel and Access files into a SQL Server table. The functions <b>Get-ACEData<\/b>, <b>Invoke-SqlCmd2<\/b>, <b>Write-DataTable<\/b>, and <b>Add-SqlTable<\/b> can be used to easily automate your Excel and Access data loads.<\/p>\n<p>MC, that is all there is to using Windows PowerShell and ACE Drivers to get data out of Microsoft Access and Excel files and into SQL Server. SQL Week will continue tomorrow when guest blogger Michael Wells will talk about how to automatically create tempdb files in SQL Server.<\/p>\n<p>Thank you, Chad, for an awesome blog post. <\/p>\n<p>I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Quit using deprecated JET drivers to talk to Microsoft Access and Excel. Learn how to use Windows PowerShell and ACE Drivers. &nbsp; Hey, Scripting Guy! How do I get data out of Microsoft Access and Excel files and into SQL Server by using Windows PowerShell? &mdash;MC Hello MC, Microsoft Scripting Guy, Ed Wilson, is [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[195,146,56,3,176,45],"class_list":["post-14041","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-chad-miller","tag-databases","tag-guest-blogger","tag-scripting-guy","tag-sql-server","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Quit using deprecated JET drivers to talk to Microsoft Access and Excel. Learn how to use Windows PowerShell and ACE Drivers. &nbsp; Hey, Scripting Guy! How do I get data out of Microsoft Access and Excel files and into SQL Server by using Windows PowerShell? &mdash;MC Hello MC, Microsoft Scripting Guy, Ed Wilson, is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/14041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=14041"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/14041\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=14041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=14041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=14041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}