Setup connection to VC API using powershell - VisualCron - Forum

Community forum

S.Servicedesk
2021-04-22T09:59:44Z
I am working with the powershell sample provided in the visualcron installation directory.
Why i run that sample (with some minor) updates i get the below error:
S.Servicedesk
2021-04-22T10:01:47Z
Ok, something went wrong during the post of this topic.
The error i was referring to in my post was:

Exception calling "Connect" with "2" argument(s): "Object reference not set to an instance of an object."
At line:34 char:6
+         $Global:Server = $Client.Connect($conn, $true);
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

S.Servicedesk
2021-04-23T09:02:52Z
hi,

I managed to clear the error using the below code, however, the connection is still not being made with the VC server.
It seems that the script is executed but there is no connection being allowed by the VC server, it seems the server is not allowed to connect back to itself somehow.
Please note that i am running this code from VC itself, using the powershell execute task.


$Client     = New-Object -TypeName VisualCronAPI.Client

$conn = New-Object VisualCronAPI.Connection
$conn.Address = "{COMPUTER(Name)}"
$conn.username = "Test_User"
$conn.password = "************"
$client.Connect($conn,$true,$true)



Support
2021-04-23T13:21:34Z
Originally Posted by: S.Servicedesk 

hi,

I managed to clear the error using the below code, however, the connection is still not being made with the VC server.
It seems that the script is executed but there is no connection being allowed by the VC server, it seems the server is not allowed to connect back to itself somehow.
Please note that i am running this code from VC itself, using the powershell execute task.


$Client     = New-Object -TypeName VisualCronAPI.Client

$conn = New-Object VisualCronAPI.Connection
$conn.Address = "{COMPUTER(Name)}"
$conn.username = "Test_User"
$conn.password = "************"
$client.Connect($conn,$true,$true)





Does it behave the same way if you use the Execute task instead of the powershell task? In command, write the path to the powershell.exe, in argument, write the path to the powershell script file

Michael
Support
http://www.visualcron.com 

Please like  VisualCron on facebook!
S.Servicedesk
2021-04-23T14:12:35Z
Hi Michael,

I had to make an update the script in order to run it as an ps1 file. The output of the script is the same. There is no connection made to the VC server.

Add-Type -Path "E:\Apps\VisualCron\VisualCronAPI.dll"
Add-Type -Path "E:\Apps\VisualCron\VisualCron.dll"

$Client     = New-Object -TypeName VisualCronAPI.Client

$conn = New-Object VisualCronAPI.Connection
$conn.Address = $env:COMPUTERNAME
$conn.username = "Test_User"
$conn.password = "**************"
$client.Connect($conn,$true,$true)
Support
2021-04-29T15:39:25Z
Can you confirm if you try to connect locally on the Server or to another Server in the network?
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
S.Servicedesk
2021-05-19T11:17:38Z
Originally Posted by: Support 


Does it behave the same way if you use the Execute task instead of the powershell task? In command, write the path to the powershell.exe, in argument, write the path to the powershell script file



Hi,
When you execute the commands using a powershell file (.ps1) there error is the same.
Support
2021-05-19T15:07:29Z
I am not sure you answered my question. What if you connect locally on the server (from the powershell script).
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
bweston
2021-05-24T15:50:23Z
If I remember correctly, somewhere along the line it became necessary in my experience for CommClient.dll, CommClientCore.dll, and CommServer.dll to be in the Powershell subfolder of the Visualcron installation directory. I subsequently discovered that using a reparse point (hardlink, I think?) worked and persisted across Visualcron upgrades, as a result of which I haven't thought about it for a long time. Not sure whether it might pertain to your issue.

I also add-type the DLLs in the opposite order and use active directory for most of my connections, just to cover another couple of possibly irrelevant differences.
Support
2021-05-31T09:25:47Z
You should delete these files. Only use VisualCronAPI.dll and VisualCron.dll. The latest version of Comm.. is embedded so you might have a conflict if you keep these files.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
bweston
2021-06-02T14:13:36Z
Well, that's disconcerting to hear, since with the symbolic links removed I still get errors. If I get time for it later I will post another thread rather than hijacking this one, but for now I will need to put them back. It is worth noting that it is not the same error originally reported here.

S.Servicedesk, you said you cleared the error using your second code example but still weren't getting a connection. Are you still getting an error message or just no output? How are you determining that no connection is established? Are you checking the client connections from the GUI or perhaps the Visualcron logs? I noticed that your sample code doesn't assign the result of the call to $client.Connect to a variable in order to call any of the methods that send commands to the server, nor does it explicitly disconnect the client; I'm just taking some shots in the dark though.
Scroll to Top