Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


Rami Aboulissane
2023-06-18T20:10:41Z
Hello,

I am trying to create a function that Exports all settings in VisualCron via Powershell through VisualCron API

I first create a function to load the DLLS

Then I create the function to establish a connection

These work fine

I however struggle with inputing a value in the ExportSettings() method that is accepted. I always get a null value no matter what I try.

#Function that loads VisualCron's API dlls.
function Load-VCAPIDLL {
param(
[Parameter()]
[string]$VCPath = "C:\Program Files (x86)\VisualCron\VisualCron.dll",

[Parameter()]
[string]$VCAPIPath = "C:\Program Files (x86)\VisualCron\VisualCronAPI.dll"
)

$VC = [Reflection.Assembly]::LoadFrom($VCPath);
$VCAPI = [Reflection.Assembly]::LoadFrom($VCAPIPath);
}

#Returns a VisualCronAPI.Server object that can be used to interact with target VisualCron server.
function ConnectTo-VCServer {
param(
[Parameter(Mandatory=$true)]
[string]$username,

[Parameter(Mandatory=$true )]
[string]$password,

[Parameter( Mandatory=$true)]
[alias("address")]
[string]$VCServerAddress,

[Parameter( Mandatory=$true )]
[alias("connection")]
[string]$VCServerConntype,

[Parameter()]
[alias("port")]
[string]$VCServerPort
)

#Call the dll loading fn
Load-VCAPIDLL

#Create new connection objects
$ClientConnectionObj =New-Object -TypeName VisualCronAPI.Client
$ServerConnectionObj = New-Object -TypeName VisualCronAPI.Server
$APIConnectionObj = New-Object -TypeName VisualCronAPI.Connection

#Assign provided params to APIConnectionObj
$APIConnectionObj.Address = $VCServerAddress
$APIConnectionObj.UserName = $username
$APIConnectionObj.PassWord = $password

if ($VCServerPort -ne $null)
{
$APIConnectionObj.Port
}

$APIConnectionObj.ConnectionType = $VCServerConntype

#Using the ClientConnectionObj, pass in the APIConnectionObj to update ServerConnectionObj.
#This creates a connection to the target VisualCron server.
$ServerConnectionObj = $ClientConnectionObj.Connect($APIConnectionObj, $true)

#Return VisualCronAPI.Server object
Return $ServerConnectionObj
} 

##Export VisualCron settings to import in QA environment

function Export-VCSettings {
param(
[Parameter(Mandatory=$true)]
[string]$Usedefaultfile,

[Parameter(Mandatory=$true )]
[string]$IncludeallConnections,

[Parameter( Mandatory=$true)]
[string]$IncludeAllCredentials,

[Parameter( Mandatory=$true )]
[alias("Svrsettings")]
[string]$IncludeAllServerSettings,

[Parameter()]
[alias("InclAllJobs")]
[string]$IncludeAllJobs,

[Parameter()]
[alias("InclAllPerm")]
[string]$IncludeallPermissions,

[Parameter()]
[alias("IncludeCerts")]
[string]$IncludeAllCertificates,

[Parameter()]
[alias("JobObjects")]
[string]$Jobjcts

)
{
$global:Server = New-Object VisualCronAPI.Server
$eip = New-Object VisualCron.ExportImportProgressClass
$eip.UseDefaultFile = $Usedefaultfile
$eip.IncludeAllCertificates = "true"
$eip.IncludeAllConnections = $IncludeallConnections
$eip.IncludeAllCredentials = $IncludeAllCredentials,
$eip.IncludeAllServerSettings = $IncludeAllServerSettings
$eip.IncludeAllJobs = $IncludeAllJobs
$eip.IncludeAllPermissions = $IncludeallPermissions
$eip.JobObjects = $global:Server.jobs.GetAll()
}

$escr = New-Object VisualCron.ExportSettingsResponseClass
$escr = $global:Server.ExportSettings($eip)

if ($escr.Success -and $escr.FileBytes -ne 'null') {

[system.IO.File.Writeallbytes]::("c:\VC-Settings.zip", $escr.FileBytes)

}}


However it keeps telling me the below

You cannot call a method on a null-valued expression.
At line:47 char:1
+ $escr = $global:Server.ExportSettings($eip)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull



I was basing this off of a C# example someone had posted

[img]https://ssctechnologiesinc-my.sharepoint.com/:i:/g/personal/raboulis_ssnc-corp_global/ES70tmLsOxhJgxr5PCtk8pwBnhs5CV2kxmKOlkdT1tGOsg?e=ONYUka[/img]



Any ideas what I need to put in the ExportSettings method as a value? I thought passing through the variables for the ExportImportProgress class



Sponsor
Forum information
Rami Aboulissane
2023-06-20T10:35:18Z
Does anyone still use these forums?
thomas
2023-06-20T13:06:46Z
Not sure to be honest. There is so much spam in the forum now, that it is becoming unusable. Since VC Support has abandoned the forum, maybe it would be an idea for the registered (real) users to create a Discord og Slack channel for helping each other out.

Anyway, I can't help you with powershell unfortunaltely
Scroll to Top