使用Powershell创建空白访问数据库 [英] Create Blank Access Database Using Powershell

查看:96
本文介绍了使用Powershell创建空白访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我会先研究一两天所需的主题,然后在这里询问,但是我一直在努力寻找有关此主题的所有信息.

Normally I'd research the topic I need for a day or 2 and then ask here, but I've been struggling to find anything at all about this topic.

有人知道如何使用PowerShell(V3)创建具有定义的表和列标题的新Access 2010 MDB文件吗?

Does anyone know how to use PowerShell (V3) to create a new Access 2010 MDB file, with a defined table and column headings?

感谢您的指导.

推荐答案

找到了一些!为了所有人的利益,下面是代码:

Found some! Just for interests sake for anyone checking, here is the code:

Function Create-DataBase($Db){
 $application = New-Object -ComObject Access.Application
 $application.NewCurrentDataBase($Db,10)
 $application.CloseCurrentDataBase()
 $application.Quit()
}
Function Invoke-ADOCommand($Db, $Command){
 $connection = New-Object -ComObject ADODB.Connection
 $connection.Open("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=$Db")
 $connection.Execute($command)
 $connection.Close()
}
$Db = "C:\ScheduledCodeRun\CollatedData\Test.mdb"
$table = "MyTest"
$Fields = "F1 Counter, F2 Date, F3 Integer, F4 Text"
$command = "Create Table $table($fields)"
If(Test-Path $Db){
    Write-Host 'DB already exists' -fore green
}else{
    Create-DataBase $db
    Invoke-ADOCommand $Db 'Create Table MyTest(F1 Counter, F2 Date, F3 Integer, F4 Text)'
}

这篇关于使用Powershell创建空白访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆