Powershell cannot create Excel object - powershell

I have a Win11 PC with Office365 and another Win11 PC with Office 2010
The PC with Office 2010 cannot create an Excel object in Powershell.
Here is my script:
$excel = New-Object -ComObject excel.application
$excel.Visible = $true
$workbook = $excel.Workbooks.Add(1)
$Worksheet = $workbook.worksheets.Item(1)
$ActiveWindow = $excel.ActiveWindow
Works fine on the Office365 machine, creates and opens a spreadsheet.
On the Office 2010 machine I get this error:
Exception setting "Visible": "Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type
'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the
interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception
from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))."
At line:2 char:1
I am missing something obvious which has got me baffled.
Any ideas or suggestions.
The Office2010 PC has been repaired using a recovery USB to fix other issues. The trial version of Office365 was uninstalled and Office 2010 installed

Related

Create New Outlook 365 Email in PowerShell

I'm trying to create an Outlook email in PowerShell, and I've found the same code everywhere to do it:
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$mail.Subject = "<Subject>"
$mail.Body = "<Body>"
and then either
$inspector = $mail.GetInspector
$inspector.Display()
Or
$mail.Display()
to show the email.
However, at the very first line I get this error:
New-Object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
I've tried it without the -comObject and get a different error:
New-Object : Cannot find type [Outlook.Application]: verify that the assembly containing this type is loaded.
I've tried loading the assembly with
[Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Outlook") | out-null
but still get the same error messages when running the previous commands.
In case it matters, we are using Office 365, but I do have a local copy of Office installed. Is there a different type of object I need to use with Office 365?
Also, it looks like it's trying to reach out to a server to create the object. Is there a way for me to force it to do so locally?
CO_E_SERVER_EXEC_FAILURE means Outlook is running in a security context different from that of your app. COM system refuses to marshal calls between processes running in different security contexts.

How to access mdb file in windows10 by 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 ;)

PowerShell imported dll not working: Exception calling "ReadLookupTables" with "0" argument(s): "Object reference not set to an instance of an object

i have currently an issue with a powershell script i have developed.
The following script runs on my system and on another developer machine but not on any other system... I have tested it on a virtual Win10 hyper v but it's always the same error:
Exception calling "ReadLookupTables" with "0" argument(s): "Object reference not set to an instance of an object.
The script code:
$pwaUrl = "https://xyz.co"
$userName = "xyz"
$password = "xyz"
Import-Module "$PSScriptRoot\ProjectHelper\Microsoft.ProjectServer.dll"
$projHelper = New-Object Microsoft.ProjectServer.MsProject($pwaUrl, $username, $password, $true)
$secSvc = $projHelper.GetSecuritySvc();
$secGroups = $secSvc.readGroupList();
$secGroups
On the developer machines Visual Studio Enterprise is installed... I have added all the SDK's and .Net Runtime environments on my virtual machine but it does not work.
Thanks for help
I have found a solution for my issue.
I've opened the dll with the Microsoft dll disassembler and checked on the Manifest the required dll for this dll...
Than i compared the dlls on my system with the other system and copied the missing files into the "$PSScriptRoot\ProjectHelper\Microsoft.ProjectServer.dll" folder
now it's working...

PowerDesigner COM object is empty on Windows Server 2012

We have a problem when scripting PowerDesigner on Windows Server 2012.
We don't have problems on Windows 10 and Windows 7 (we tried it on several machines).
We are starting PowerDesigner from PowerShell like this:
$PowerDesigner = New-Object -com powerdesigner.application
Add-Type -path “C:\Program Files (x86)\Sybase\PowerDesigner 16\Interop.PdCommon.dll”
Add-Type -path “C:\Program Files (x86)\Sybase\PowerDesigner 16\Add-ins\Microsoft SQL Server 2005 Analysis Service\Interop.PdPDM.dll”
On Windows Server 2012 R2 all properties of the $PowerDesigner object are set to $null.
If we try to set a property to some other value we get an error.
For example, the statement
$PowerDesigner.InteractiveMode = 1
fails with the following error:
Exception setting "InteractiveMode": "Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))"
The PowerDesigner version is 16.1.0.3637.

Is there anyway to connect to SSAS using Service account while using powerpivot to get the data from cube?

We are using Excel 2010 into our office to produce some reports. We are using powerpivot plug in to connect to SSAS cube. The only problem is when, it is using windows authentication and I want to use SQL Server Service Account instead of windows account. I went to advance connection and tried to type my user id and password but it is greyed out?
Any help would be really appreciated.
I am using this powershell script which opens the Excel file and refresh it.
``1. Dir "C:\Users\New folder" -Recurse | % {
$ExcelObject = New-Object -ComObject Excel.Application
$ExcelObject.Visible = $false
$ExcelObject.DisplayAlerts = $false
$WorkBook = $ExcelObject.Workbooks.OpenXML($_.FullName)
$WorkBook.RefreshAll()
$WorkBook.Save()
$WorkBook.Close()
$ExcelObject.Quit()
}
SSAS only accepts Windows auth. But you can close all Excel windows then start Excel from a command line like this:
runas /netonly /user:REALDOMAIN\YOURDOMAINUSERNAME "c:\path\to\excel.exe"
Then when it connects to Windows auth resources remotely it will connect as the user you mention in the runas command.