I have this script that I have stolen and modified from other answers here at TechNet:
Can someone please tell me where I'm going wrong?
# Creates new blank Access database.
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 = "col1 Text, col2 Text, col3 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(col1 Text, col2 Text, col3 Text)'
}
When I run the script in PowerShell ISE, it creates the new Access Database fine. However, when I run it in PowerShell command line, it doesn't.Can someone please tell me where I'm going wrong?