使用Powershell连接到Microsoft Access DB / SharePoint列表

时间:2018-04-09 20:09:22

标签: powershell ms-access sharepoint ado

我正在尝试使用Powershell连接到托管SharePoint列表的Microsoft Access数据库。但是我似乎无法在网上找到准确的信息来证明如何做到这一点。我对SharePoint比较陌生,但对Powershell很满意。

我发现的最接近的演示来自Microsoft脚本专家,在this page的第一个脚本中:

$path = "C:dataScriptingGuysHSG_8_10_09HighJumperDatabase.mdb"
$adOpenStatic = 3
$adLockOptimistic = 3

$cn = new-object -comobject ADODB.Connection
$rs = new-object -comobject ADODB.Recordset

$cn.Open("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = $path")
$rs.Open("SELECT TOP 1 [High Jumper Data].[Name], 
  [High Jumper Data].[Personal Best], [High Jumper Data].[Season Best] 
  FROM [High Jumper Data]
  ORDER BY [High Jumper Data].[Personal Best] 
  DESC , [High Jumper Data].[Season Best] DESC", 
  $cn, $adOpenStatic, $adLockOptimistic)

$rs.MoveFirst()
Write-host "The winner will likely be " $rs.Fields.Item("Name").Value

不幸的是我从来没有使用过ADO,也不确定这里引用的Provider参数是什么。

我的目标是在SharePoint列表中查询某些信息,然后将该信息复制到其他位置。是否有类似的PowerShell对象/命令为此目的复制此脚本?或者我是否需要学习ADO才能访问Access上的SharePoint列表?

1 个答案:

答案 0 :(得分:0)

部分"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = $path"是连接字符串,由两部分组成,即提供者和数据源

Provider参数定义了如何从Access获取数据的技术。在这种情况下,它是MS JET,见:

https://docs.microsoft.com/en-us/sql/ado/guide/appendixes/microsoft-ole-db-provider-for-microsoft-jet

第二部分是您的源,即数据库所在的位置。您需要将MS Access数据库的位置设置为变量$path(第一行)

e.g。 $path = "D:\folder\myAcessDB.mdb"

,用于连接字符串的第二部分

"...DB.4.0;Data Source = **$path**"

另一种方法是直接使用powershell和sharpoint 你可以试试这篇博文教程:

https://blogs.msdn.microsoft.com/besidethepoint/2012/02/08/better-sharepoint-lists-and-list-items-in-powershell/