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