To use the data to connect to the database first, there are several ways to connect to access, I now use OLE DB connection mode. It is divided into no password and password.
No password connection text: Provider=microsoft.ace.oledb.12.0;data source=myaccessfile.accdb; Persist Security Info=false;
Have password connection text: Provider=microsoft.ace.oledb.12.0;data source=myaccessfile.accdb; Jet oledb:database Password=mydbpassword;
PowerShell new connection to use the cmdlet command, the New-object command:
$conn =new-object-typename system.data.oledb.oledbconnection $connstring
The above statement creates a new instance of the connection object first, and the variables for PowerShell are identified by $. Using the New-object command to create a new. NET object, System.Data.OleDb.OleDbConnection is the complete. NET object name, $connstring that is the beginning of the connection text, as in. NET object constructor, in order to instantiate the new object.
Then we create the command object, $cmd =new-object-typename system.data.oledb.oledbconnection $query, $conn
$query is the SQL command text, you must first open the connection $conn if you want the connection to take effect. Open ()
The Execute SQL command uses the $cmd.executenooquery () method, which returns the number of rows affected if the command executes successfully.
Do not forget to close the connection after the last operation
$conn. Close ()
The above is a recent contact with the use of PowerShell a little income, I am not a computer professional background, but work often with data, learn several ways to obtain data, recorded in this, in case of later check.
Using PowerShell to execute SQL commands in an Access environment