I found
this other answer to this question, which I modified to be the following:
*Note: I changed the $connection.Open("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=$Db") line to make the code work.
When I run that script, it creates the new Access database fine, a new table fine, but the column heading are "F1", "F2", "F3", and "F4". And if I change the text in the code to my custom names, the table won't create at all.
Can anyone help with what I'm doing wrong please?
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\Database.mdb"
$table = "Table1"
$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 Table1(F1 Counter, F2 Date, F3 Integer, F4 Text)'
}*Note: I changed the $connection.Open("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=$Db") line to make the code work.
When I run that script, it creates the new Access database fine, a new table fine, but the column heading are "F1", "F2", "F3", and "F4". And if I change the text in the code to my custom names, the table won't create at all.
Can anyone help with what I'm doing wrong please?