How to access mdb file in windows10 by powershell? - powershell

Following the suggestion that shown in the following link,
I have created a powershell script to access the mdb file.
https://devblogs.microsoft.com/scripting/hey-scripting-guy-can-i-query-a-microsoft-access-database-with-a-windows-powershell-script/
which is:
$cn = new-object -comobject ADODB.Connection
$rs = new-object -comobject ADODB.Recordset
$cn.Open("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = $path")
However, i have updated my computer to windows 10 (64bit) and installed ACCESS 2016. The powershell script does not working anymore. And it shows that the
Provider = Microsoft.Jet.OLEDB.4.0 is not found.
I have tried to change the Provider = Microsoft.ACE.OLEDB.12.0
But it does not help, as it shows the same error that the provider is not found.
Moreover, I have tried to open it with ACCESS 2016, it also does not help as it shows that can not open the database file that created in previous version.
Please help....

Thanks for whom reply my question.
Finally I got insight and find the answer myself.
I search the provider from Microsoft and find the link below.
https://www.microsoft.com/en-us/download/details.aspx?id=13255
After install the 64bit version, I can use the following code with the Microsoft.ACE.OLEDB.12.0 provider.
$cn = new-object -comobject ADODB.Connection
$rs = new-object -comobject ADODB.Recordset
$cn.Open("Provider = Microsoft.ACE.OLEDB.12.0;Data Source = $path")

If Win 10 OS 64 bits with MS Office 32bits / click2run , use 32bits Powershell ;)

Related

Open User Profile In Chrome using PowerShell and Selenium

So I have found little to no info on this topic, basically I'm just trying to use selenium to open up a chrome profile so that the settings are saved to be used in each run of the script. Please help as I am new to coding and have never used PowerShell.
So far the only semi successful attempt with no errors is as follows but still does not work..
$WebDriverPath = Resolve-Path "C:\selenium\WebDriver.dll"
Unblock-File $WebDriverPath
Add-Type -Path $WebDriverPath
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$CD = $ChromeDriver.AddArgument("--user-data-dir=C:\Users\jshaw\AppData\Local\Google\Chrome\User Data\Profile 2")
$CD = New-Object OpenQA.Selenium.Chrome.ChromeDriver
$CD.Navigate().GoToURL('https://www.google.com')
So i figured out how to do this! This loads your default profile; however, there is an issue when you do this. If you have Chrome open already it throws an error. when Chrome is closed all good! Now I know why people use customized profiles.
$ChromeOptions.AddArgument(
"--user-data-dir=C:\Users\TweakAir\AppData\Local\Google\Chrome\User Data"
)
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeOptions)
$ChromeDriver.Navigate().GoToURL($YourURL)```

Powershell script gives wrong Windows Updates information

I have the below script to detect Windows Updates that are not installed, however it always says IsDownloaded = false, but they are downloaded, I have windows updates set to Download Only. Anyone know why its not returning the correct info?
$updatesession = [activator]::CreateInstance([type]::GetTypeFromProgID("Microsoft.Update.Session"))
$updatesearcher = $updatesession.CreateUpdateSearcher()
$searchresult = $updatesearcher.Search("IsInstalled=0")
$searchresult
I am using windows server 2016.

how to connect oracle database and run query by powershell

How can I connect to an Oracle database (11g)? I have a list of oracle servers and I want to execute a query on them from Jump Server (the Jump server has Powershell v2).
Servers are accessible from Jump Server as I am able to access them by UNC path.
Update:
I know it can be done by using ODP.Net connector. But i don't want to use it due to approval.
You can try the method using an OleDbConnection described here
function Get-OLEDBData ($connectstring, $sql) {
$OLEDBConn = New-Object System.Data.OleDb.OleDbConnection($connectstring)
$OLEDBConn.open()
$readcmd = New-Object system.Data.OleDb.OleDbCommand($sql,$OLEDBConn)
$readcmd.CommandTimeout = '300'
$da = New-Object system.Data.OleDb.OleDbDataAdapter($readcmd)
$dt = New-Object system.Data.datatable
[void]$da.fill($dt)
$OLEDBConn.close()
return $dt
}

Method invocation failed because [System.__ComObject] does not contain a method named 'Close' in Powershell v4.0

this is my first StackOverflow question, but I will try to keep the community standards in mind..
I am running Office 2013 on Win7 Pro and PoSh v4.0. Upon execution of the subsequent script, I receive the following error: "Method invocation failed because [System.__ComObject] does not contain a method named 'Close'."
$xl = New-Object -comobject Excel.Application
$xl.Visible = $false
$xl.DisplayAlerts = $false
$filepath = "C:\Users\rysullivan\Desktop\Projects\EDCautomation\attach\"
$wb1 = $xl.Workbooks.Open((Join-Path $filepath "Ryan Sullivan-Template.xlsx"))
sleep 5
$wb1.Close()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl)
In keeping with the standard of presenting the shortest code that will reproduce the error, I developed the above code down from a larger automation
Powershell 4.0 and Excel 2013 | Bug | Work-a-round seemed to be getting at the same point. I followed the thread/culture solution offered by XXInvidiaXX and the same error was generated.
Problems with Excel automation in PowerShell had an answer by Roy that pointed to a timing error, but I inserted a Sleep command and tried running the open and close commands separately, both to no avail.
Any help, especially underlying theory, is greatly appreciated.
Even though the arguments to Workbook.Close() are all optional, all the examples on MSDN provide at least one (the SaveChanges argument), leading me to believe that PowerShell does not recognize the method signature when you don't provide any arguments.
You might have better luck with:
$wb1.Close($false)
or
$wb1.Close($false,$null,$null)
Substitute with $true to save any changes you may have made
I tend to use a method of Quit() at the level of the Excel process ($xl in this case), rather than the workbook ($wb1).
So using your code, it would be written as follows (with $xl.Quit() instead of $wb1.Close()):
$xl = New-Object -comobject Excel.Application
$xl.Visible = $false
$xl.DisplayAlerts = $false
$filepath = "C:\Users\rysullivan\Desktop\Projects\EDCautomation\attach\"
$wb1 = $xl.Workbooks.Open((Join-Path $filepath "Ryan Sullivan-Template.xlsx"))
sleep 5
$xl.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl)
Also be sure to run it as administrator.

How to modify COM+ applications from powershell

I am automating the creation of a web server. An application is created for me, but I need to manually change the Identity of a COM+ Application to run as a specific user.
Being a linux admin with little experience with powershell, I'm in over my head. It looks like there is an API to modify COM+ applications.
https://msdn.microsoft.com/en-us/library/ms679173(v=vs.85).aspx
From this stackoverflow question, I've gotten this far in modifying the application
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
$apps = $comAdmin.GetCollection(“Applications”)
$apps.Populate();
I am able to see my application in the list by typing in this command
$apps
Is it possible to modify the foobar application Identity from powershell?
Thanks to this stackoverflow question, I got it working.
$targetApp = "examplecompany"
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
$apps = $comAdmin.GetCollection("Applications")
$apps.Populate();
$app = $apps | Where-Object {$_.Name -eq $targetApp}
$comAdmin.ShutdownApplication($targetApp)
$app.Value("Identity") = 'example.com\exampleuser'
$app.Value("Password") = 'correct-horse-battery-staple'
$apps.SaveChanges()
$comAdmin.StartApplication($targetApp)