PowerShell非常新,但想知道以下是否可行......
我想扩展以下脚本(只需打开一个AccessDB,运行快速查询并显示其结果)。
可以将Query1(简单表格)的结果复制或导出到Excel文档中吗?
$Acc = New-Object –com Access.Application
#Opens the Access Database
$Acc.OpenCurrentDataBase("TEST.mdb")
#Runs the queries
$Acc.DoCmd.OpenQuery("QUERY1")
答案 0 :(得分:1)
使用此示例为您提供一个关闭:
$path = "C:\database.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
您可以获得更多详细信息:
microsoft-access-database-with-PS
更多带脚本和功能的指南:
希望它有所帮助。