Highlighted
Aniltkp Frequent Contributor.
Frequent Contributor.
242 views

Error connecting to HPRM from powershell

Jump to solution

Hi There,

can somebody help me to overcome the below problem. if there are nay relevant posts, code samples would be great.

I am trying to download files from HP records manager using document id.

I have this working in a excel using macro. I am trying to develop powershell script so that I can automate this easily 

can some one help me troubleshoot the below issue.

is it because of any package required to import. if you have a working script please share there is no much help on google for this topic.

thank you.

kumar

----------------------------------------------

Add-Type -Path "C:\Program Files (x86)\Hewlett-Packard\HP Records Manager\HP.HPTRIM.SDK.dll"

$db = New-Object HP.HPTRIM.SDK.Database

$db.Dispose()

Results

New-Object : Exception calling ".ctor" with "0" argument(s): "The type initializer for 'HP.HPTRIM.SDK.trimPINVOKE' threw an exception."
At line:3 char:8
+     $db = New-Object HP.HPTRIM.SDK.Database
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
 
You cannot call a method on a null-valued expression.
At line:5 char:5
+     $db.Dispose()
+     ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

0 Likes
1 Solution

Accepted Solutions
Super Contributor.. davros29 Super Contributor..
Super Contributor..

Re: Error connecting to HPRM from powershell

Jump to solution

Can you double check that you're running the x86 version of PowerShell if you've installed the 32-bit version of TRIM?

0 Likes
10 Replies
Super Contributor.. davros29 Super Contributor..
Super Contributor..

Re: Error connecting to HPRM from powershell

Jump to solution
# Load the .NET version of the SDK
try {
    [reflection.assembly]::LoadWithPartialName("HP.HPTRIM.SDK") | Out-Null
    [HP.HPTRIM.SDK.TrimApplication]::Initialize()
    Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tINFO`tTRIM library loaded OK." -OutVariable +log
} catch {
    Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tERROR`tCould not load TRIM library. Exiting." -OutVariable +log
    Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tERROR`tThis is probably a 32/64 bit problem." -OutVariable +log
    Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tERROR`t$($_.Exception.Message)" -OutVariable +log
    $log | Out-File $logFile
    return
}

# Connect to TRIM
try {
    $trimdb = New-Object HP.HPTRIM.SDK.Database
    $trimdb.WorkgroupServerName = $trimWorkgroup
    $trimdb.Id = $trimDatasetID
    $trimdb.Connect()
    Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tINFO`tConnected to TRIM dataset $trimDatasetID on $trimWorkgroup." -OutVariable +log
} catch {
    Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tERROR`tCould not connect to TRIM. Exiting." -OutVariable +log
    Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tERROR`t$($_.Exception.Message)" -OutVariable +log
    $log | Out-File $logFile
    return
}

 

See above for the snippets of code I use to load the SDK and connect to TRIM in PowerShell. Hope that helps.

At the end of the script I call these.

$trimdb.Disconnect()
$trimdb.Dispose()

 

0 Likes
Aniltkp Frequent Contributor.
Frequent Contributor.

Re: Error connecting to HPRM from powershell

Jump to solution
Hi,
Thanks for the reply. I have path issue. due to permissions I can not change the default paths.
my assembly's are located: C:\WINDOWS\assembly\HP.HPTRIM.SDK\
is there any work around.
thanks


PS C:\WINDOWS\system32> # Load the .NET version of the SDK
try {
[reflection.assembly]::LoadWithPartialName("HP.HPTRIM.SDK") | Out-Null
[HP.HPTRIM.SDK.TrimApplication]::Initialize()
Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tINFO`tTRIM library loaded OK." -
} catch {
Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tERROR`tCould not load TRIM library. Exiting."
Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tERROR`tThis is probably a 32/64 bit problem."
Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")`tERROR`t$($_.Exception.Message)"
return
}


2019-09-16 10:21:01 ERROR Could not load TRIM library. Exiting.
2019-09-16 10:21:01 ERROR This is probably a 32/64 bit problem.
2019-09-16 10:21:01 ERROR Exception calling "Initialize" with "0" argument(s): "HP.HPTRIM.SDK.dll - Unable to load tsjApi.dll. Additional information follows.
TrimApplication.TrimBinariesLoadPath: <not set>
Trying assembly directory. Search path: C:\WINDOWS\assembly\GAC_MSIL\HP.HPTRIM.SDK\8.0.0.0__93ab772ef8ad9a2e\tsjApi.dll . File does not exist.
Trying parent directories of assembly directory. Search path: C:\WINDOWS\assembly\GAC_MSIL\HP.HPTRIM.SDK\8.0.0.0__93ab772ef8ad9a2e\tsjApi.dll . File does not exist.
Trying parent directories of assembly directory. Search path: C:\WINDOWS\assembly\GAC_MSIL\HP.HPTRIM.SDK\tsjApi.dll . File does not exist.
Trying parent directories of assembly directory. Search path: C:\WINDOWS\assembly\GAC_MSIL\tsjApi.dll . File does not exist.
Trying parent directories of assembly directory. Search path: C:\WINDOWS\assembly\tsjApi.dll . File does not exist.
Trying parent directories of assembly directory. Search path: C:\WINDOWS\tsjApi.dll . File does not exist.
Trying parent directories of assembly directory. Search path: C:\tsjApi.dll . Error: %1 is not a valid Win32 application
Note: This error is most likely due to an x86/x64 architecture mismatch.
Trying PATH entries. Search path: C:\Program Files (x86)\Hewlett-Packard\HP Records Manager\tsjApi.dll . Error: %1 is not a valid Win32 application
Note: This error is most likely due to an x86/x64 architecture mismatch.
"
0 Likes
Super Contributor.. davros29 Super Contributor..
Super Contributor..

Re: Error connecting to HPRM from powershell

Jump to solution

Can you double check that you're running the x86 version of PowerShell if you've installed the 32-bit version of TRIM?

0 Likes
Aniltkp Frequent Contributor.
Frequent Contributor.

Re: Error connecting to HPRM from powershell

Jump to solution
I am not sure how to check the TRIM bit version.
from HPrecords manager setupinfo:
version: 8
Build: 1.1.7898

powershell info as below:
PS C:\WINDOWS\system32> Get-Host


Name : Windows PowerShell ISE Host
Version : 5.1.14409.1018
InstanceId : 7d1a8131-0293-4e15-80b3-b00d046096a5
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-AU
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
thanks
0 Likes
Super Contributor.. davros29 Super Contributor..
Super Contributor..

Re: Error connecting to HPRM from powershell

Jump to solution

When you run PowerShell, are you picking the (x86) version? That's the 32-bit version. If PowerShell doesn't have an (x86) in its name, then it's the 64-bit version. The error you're getting looks like you're trying to load a 32-bit DLL in a 64-bit PowerShell. 

Untitled.png

0 Likes
Aniltkp Frequent Contributor.
Frequent Contributor.

Re: Error connecting to HPRM from powershell

Jump to solution
I am using windows 8 OS with 64 bit.
I am launching PowerShell from : C:\Windows\System32\WindowsPowerShell\v1.0

0 Likes
Jamie Smith Super Contributor.
Super Contributor.

Re: Error connecting to HPRM from powershell

Jump to solution

I agree with Davros29.  It does look like you have TRIM x86 installed instead of x64.  You can verify this by looking at the 'programs and features' control panel in Windows.  If you see don't see 'x64' at the end of the program entries for HP/HPE/Records Manager/Content Manager etc, then you have the x86 version of TRIM installed and you will need to launch the x86 version of powershell.

Aniltkp Frequent Contributor.
Frequent Contributor.

Re: Error connecting to HPRM from powershell

Jump to solution
Hi Smith,
from control panel My records manager is showing x86 which means 32 bit as you described.
--------------------
I do not have 32 bit powershell. is there any work around.
------
In Windows® 8.1
•On the Start screen, type Windows PowerShell (x86). Click the Windows PowerShell x86 tile.
•If you are running Remote Server Administration Tools for Windows 8.1, you can also open Windows PowerShell x86 from the Server ManagerTools menu. Select Windows PowerShell (x86).
•On the desktop, move the cursor to the upper right corner, click Search, type PowerShell x86 and then click Windows PowerShell (x86).
•Via command line, enter: %SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe


0 Likes
Jamie Smith Super Contributor.
Super Contributor.

Re: Error connecting to HPRM from powershell

Jump to solution

Can't you use one of those methods you listed from Microsoft's web site?  If you can't run x86 powershell, then you can install x64 TRIM instead, or write a 32bit TRIM SDK program to do the equivalent actions.

0 Likes
Aniltkp Frequent Contributor.
Frequent Contributor.

Re: Error connecting to HPRM from powershell

Jump to solution
Either of two actions are not possible.
Thanks for your assistance. @ davrose29 & @Jamie Smith.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.