Install MS Access DAO Primary Interop Assembly for Use with PowerShell Script - powershell

I am trying to automate Microsoft Access 2016 with PowerShell, but I appear to be missing an Office Primary Interop Assembly called Microsoft.Office.Interop.Access.Dao. I've tried a few approaches in PowerShell, and these are the errors that I get:
PS > $app.Application.OpenCurrentDatabase()
The following exception occurred while retrieving member "Application": "Could not load file or assembly 'Microsoft.Office.Interop.Access.Dao, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified."
At line:1 char:1
+ $app.Application.OpenCurrentDatabase()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : CatchFromBaseGetMember
PS > Add-Type -Assembly "Microsoft.Office.Interop.Access.Dao"
Add-Type : Could not load file or assembly 'Microsoft.Office.Interop.Access.Dao, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
At line:1 char:1
+ Add-Type -Assembly "Microsoft.Office.Interop.Access.Dao"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.AddTypeCommand
Please note the difference in version (15.0.0.0 vs 12.0.0.0).
The only version of Office that I have installed on this machine is Office 2016 via Office 365 download. I have run gacutil /l from a Visual Studio Command Prompt, and I see that the other Office PIAs, version 15.0.0.0, are installed.
According to the NuGet Web site, I could download the assembly via NuGet Package Manager Console, if I were working on a Visual Studio Solution, but I cannot install the assembly with PowerShell:
PS > Install-Package Microsoft.Office.Interop.Access.Dao
Install-Package : No match was found for the specified search criteria and package name 'Microsoft.Office.Interop.Access.Dao'. Try Get-PackageSource to see all available registered package sources.
At line:1 char:1
+ Install-Package Microsoft.Office.Interop.Access.Dao
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
My questions are:
How can I install Microsoft.Office.Interop.Access.Dao to the GAC
so I can reference it in PowerShell scripts?
If nuget.org is listed as a PackageSource in PowerShell, why can't I use the Install-Package command to install this assembly?
Why did this assembly not get installed with Office 2016/365?
The accepted answer will provide at least a solution to my first question - How can I install Microsoft.Office.Interop.Access.Dao to the GAC so I can reference it in PowerShell scripts?

Related

"Unable to load one or more of the requested types" Exception occurred when installing npgsql

all.
I installed npgsql on Windows Server 2022 by the following step.
PS > Install-Package -Name Npgsql -Source https://www.nuget.org/api/v2 -SkipDependencies
PS > Add-Type -Path "C:\Program Files\PackageManagement\NuGet\Packages\Npgsql.6.0.5\lib\net6.0\Npgsql.dll"
However, I got the following error.
Add-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more
information.
At line:1 char:1
+ Add-Type -Path "C:\Program Files\PackageManagement\NuGet\Packages\Npg ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], ReflectionTypeLoadException
+ FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.AddTypeComma
nd
Would you tell me the solution?

sharpdevelop nuget: set-project says unknown project

I am trying to follow this post
to add nuget packages to my solution through the command line.
However, when I try to run the following command:
Install-package nuget -solution mysolution.sln -projectName myproject
I get the following error,
Can't read Microsoft Solution file format 12.00
Install-Package : A project must be open to run this command.
At line:1 char:16
+ install-package <<<< nuget -solution mysolution.sln -projectname
myproject
+ CategoryInfo : InvalidOperation: (:) [Install-Package], Invalid OperationException
+ FullyQualifiedErrorId : NoProjectOpen,ICSharpCode.PackageManagement.Cmdlets.InstallPackageCmdlet
Based on this post, I tried setting the project name
set-project myproject mysolution.sln
I get this error,
Can't read Microsoft Solution file format 12.00
Set-Project : Unknown project: myproject
At line:1 char:12
+ set-project <<<< myproject mysolution.sln
+ CategoryInfo : NotSpecified: (:) [Set-Project], ApplicationException
+ FullyQualifiedErrorId : System.ApplicationException,ICSharpCode.PackageManagement.Cmdlets.SetProjectCmdlet
I checked the sln file and it has the exact project name that I am trying to add. Any guesses on what could be the problem? Alternatively, is there any way to find the project names of my solution through some command so that I can cross-check?

Neo4j with Windows Powershell : xxxx is not a Neo4j Home directory

I've installed Neo4j (exe installer) and I've also extracted the powershell module from the zip file but now when I try to do anything I just get an error message like:
PS C:\dev\github\neo4j-sandbox\src\ps> Get-Neo4jServer c:\dev\github\neo4j-sandbox\neo4jdb
Get-Neo4jServer : c:\dev\github\neo4j-sandbox\neo4jdb is not a Neo4j Home directory
At line:1 char:1
+ Get-Neo4jServer c:\dev\github\neo4j-sandbox\neo4jdb
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-Neo4jServer
At first I thought perhaps I was misinterpreting what the neo4j "home directory" was and tried pointing it to the installation directory, but I just get the same error message.
PS C:\dev\github\neo4j-sandbox\src\ps> Get-Neo4jServer "c:\Program Files\Neo4j CE 2.3.2"
Get-Neo4jServer : c:\Program Files\Neo4j CE 2.3.2 is not a Neo4j Home directory
At line:1 char:1
+ Get-Neo4jServer "c:\Program Files\Neo4j CE 2.3.2"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-Neo4jServer
So, what is the "Neo4j Home Directory" - I couldn't find a definition for that anywhere. Is it the data directory, or the installation directory, or something completely different.
It seems that somehow or another the installation via the exe download is different from the installation in the zip. I would have expected them to be the same, with the exe version just being automated.
Anyway, if you extract the zip file and copy the contents of the neo4j-community-2.3.2 (or appropriate for your version/edition) folder inside the zip file into a folder on your hard-drive, then point the PowerShell script at that folder it is happy to report the version of the installation.

Powershell load dll got error: Add-Type : Could not load file or assembly 'WebDriver.dll' or one of its dependencies. Operation is not supported

I want to use PowerShell with selenium and download selenium from http://www.java2s.com/Code/Jar/s/Downloadseleniumremotedriver2350jar.htm . When I try to load one of the dlls, I got errors. Hope someone can help me with it.
This is my system info.
OS Name: Microsoft Windows 7 Enterprise
OS Version: 6.1.7601 Service Pack 1 Build 7601
OS Manufacturer: Microsoft Corporation
This is my PowerShell info.
PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> $psversiontable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.18052
BuildVersion 6.3.9421.0
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40>
This is the errors I got when trying to load the dll.
PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> Add-Type -Path .\WebDriver.dll
Add-Type : Could not load file or assembly 'file:///C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40\WebDriver.dll' or one of its dependencies. Operation is
not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ Add-Type -Path .\WebDriver.dll
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> [reflection.assembly]::LoadFrom(".\WebDriver.dll")
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\test\WebDriver.dll' or one of its dependencies. The system
cannot find the file specified."
At line:1 char:1
+ [reflection.assembly]::LoadFrom(".\WebDriver.dll")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> [reflection.assembly]::LoadFrom("WebDriver.dll")
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\test\WebDriver.dll' or one of its dependencies. The system
cannot find the file specified."
At line:1 char:1
+ [reflection.assembly]::LoadFrom("WebDriver.dll")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> [reflection.assembly]::LoadFrom("C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40\WebDriver.dll")
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40\WebDriver.dll' or
one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At line:1 char:1
+ [reflection.assembly]::LoadFrom("C:\Users\test\Downloads\selenium-dotnet-2.35.0 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException
PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> [reflection.assembly]::LoadFile("C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40\WebDriver.dll")
Exception calling "LoadFile" with "1" argument(s): "An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed
in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If
this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more
information."
At line:1 char:1
+ [reflection.assembly]::LoadFile("C:\Users\test\Downloads\selenium-dotnet-2.35.0 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NotSupportedException
PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40>
If you downloaded the .DLLs from the internet, Powershell by default will not trust them. You can do one of two things here:
Unblock the content. Here's a guide with some elaboration on the problem, but essentially you just need to right-click on the downloaded file, select Properties, and click 'Unblock' in the general tab. You can unblock content directly from powershell by using the Unblock-File cmdlet.
Change your execution policy. This can also allow malicious scripts that you download to run, so be cautious.
Specifically reviewing and unblocking content you trust seems the better route, especially for your case since you seem like you would only be doing this once and you trust the package.
Edit: If that didn't solve that, the other experience I've had with this type of error is when Powershell didn't the same version of the .NET runtime as the assembly. See this question for some context, where Powershell 2.0 ran the .NET 2 runtime and the asker needed .NET 4 for some assemblies.
You're not using the same version of PS so your mileage may vary, but I would try creating/editing a config file per the linked answer to support the runtime of the DLLs you are using.
This worked for me: (from https://stackoverflow.com/a/19957173/107161)
In files:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.config C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
Run as Administrator has solved the issue, although my get-executionpolicy is allsigned

Add-Type -path "c:\Oracle\Oracle.ManagedDataAccess.dll" fails in Powershell

I'm attempting to follow the instructions according to this post for making an Oracle connection in PowerShell. When I try to load the Oracle .dll I get a operation not supported error.
PS C:\windows\system32> Add-Type -path "C:\Oracle\Oracle.ManagedDataAccess.dll"
Add-Type : Could not load file or assembly 'file:///C:\Oracle\Oracle.ManagedDataAccess.dll' or one of its dependencies.
Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:9
+ Add-Type <<<< -path "C:\Oracle\Oracle.ManagedDataAccess.dll"
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
you can try this way:
[System.Reflection.Assembly]::LoadFrom("C:\Oracle\Oracle.ManagedDataAccess.dll")
verify to have access to folder and unlocked the file.
Was resolved by adding the correct entries in TNSNAMES.ORA and restarting powershell.