Help with Powershell - VisualCron - Forum

Community forum

armo
  •  armo
  • Paid support Topic Starter
2021-02-15T13:34:10Z
I need to get active triggers for the jobs in the file. I am novice in PS and the script is made by a former employee. Can anyone help with what the $ObjData should be.

FUNCTION Get-VCAPIPath
{
$ProgramFilesPath = IF (${Env:PROCESSOR_ARCHITECTURE} -eq 'x86') { ${Env:ProgramFiles} } ELSE { ${Env:ProgramFiles(x86)} }
Join-Path $ProgramFilesPath VisualCron\VisualCronAPI.dll
}

FUNCTION Get-VCServer
{
[CmdletBinding()]
Param ([string]$ComputerName,
[int]$Port,
[System.Management.Automation.PSCredential]$Credential)

$APIPath = Get-VCAPIPath
IF (!(Test-Path $APIPath)) { Throw "VisualCron does not appear to be installed. API library not found at `"$APIPath`"." }
[Reflection.Assembly]::LoadFrom($APIPath) | Out-Null
$Conn = New-Object VisualCronAPI.Connection
$Conn.Address = IF ([String]::IsNullOrEmpty($ComputerName)) { ${Env:COMPUTERNAME} } ELSE { $ComputerName }
IF (!($Credential -eq $null))
{
$Conn.UseADLogon = $True
$NetCred = $credential.GetNetworkCredential()
$Conn.UserName = $NetCred.UserName
$Conn.Password = $NetCred.Password
}
$Client = New-Object VisualCronAPI.Client
$Client.Connect($conn)
}


#
# MAIN ROUTINE
#

$S = Get-VCServer -ComputerName LocalHost

$VCJobs = $S.Jobs.GetAll()

$AllVCJobs = @()

FOREACH ($VCJob IN $VCJobs)
{ $ObjData = New-Object System.Object

$ObjData | Add-Member -type NoteProperty -name JOBNAME -value $VCJob.Name
$ObjData | Add-Member -type NoteProperty -name JOBGROUP -value $VCJob.Group
$ObjData | Add-Member -type NoteProperty -name DESCRIPTION -value $VCJob.Description


$AllVCJobs += $ObjData
}

IF ($AllVCJobs.Count -gt 0) {$AllVCJobs | Sort-Object JobGroup, Jobname | Export-Csv -NoTypeInformation -Delimiter ";" -Path C:\TEMP\VC-JOBS.CSV}

$S.disconnect()
$S.dispose()
Gary_W
2021-02-15T15:20:33Z
I'm no expert either, but I did put together a script that reported on active jobs that had deactivated triggers. I'll call your attention to the SearchTrigs function that loops through the triggers for a job. Perhaps you can take from that what you need as you have the rest:

##
##
## DisabledTrigger - Searches active jobs for disabled file event triggers
##
##                   It's up to the user to decide if the trigger should really be enabled or not
##

# Get-VCAPIPath will get the path for VisualCron API DLLs
function Get-VCAPIPath
{
    $programFilesPath = if (${Env:PROCESSOR_ARCHITECTURE} -eq 'x86') { ${Env:ProgramFiles} } else { ${Env:ProgramFiles(x86)} }
    Join-Path $programFilesPath VisualCron\VisualCronAPI.dll
}

# Get-VCServer allows you to connect to the VisualCron Server
function Get-VCServer
{
    [CmdletBinding()]
    param ([string]$ComputerName, 
           [int]$Port,
           [System.Management.Automation.PSCredential]$Credential)

    $apiPath = Get-VCAPIPath
    if (!(Test-Path $apiPath)) { Throw "VisualCron does not appear to be installed. API library not found at `"$apiPath`"." }
    [Reflection.Assembly]::LoadFrom($apiPath) | Out-Null
    $conn = New-Object VisualCronAPI.Connection
    $conn.Address = if ([String]::IsNullOrEmpty($ComputerName)) { ${Env:COMPUTERNAME} } else { $ComputerName }
    if (!($credential -eq $null)) 
    {
        $conn.UseADLogon = $true
        $netcred = $credential.GetNetworkCredential()
        $conn.UserName = $netcred.UserName
        $conn.Password = $netcred.Password

    }
    $client = New-Object VisualCronAPI.Client
#Write-Output $conn
    $client.Connect($conn)
}

# Get-AllVCJobs returns a list of all the jobs in VisualCron server for the current machine
function Get-AllVCJobs
{
    [CmdletBinding()]
    param ([string]$ComputerName, 
           [int]$Port,
           [System.Management.Automation.PSCredential]$Credential,
           [switch]$Active)

    $ps = New-Object Collections.Hashtable($psBoundParameters)
    $ps.Remove('Active') | Out-Null
    # Connect to the Server
    $server = Get-VCServer @ps
    # Get all the jobs
    $server.Jobs.GetAll() `
    | ? { !($Active) -or $_.Stats.Active } `
    | Add-Member ScriptMethod Start { $server.Jobs.Run($this, $false, $false, $false, $null) }.GetNewClosure() -PassThru
}

# SearchTrigs will look for disabled triggers on active jobs
function SearchTrigs
{
    [CmdletBinding()]
    param ([string]$ComputerName, 
           [int]$Port,
           [System.Management.Automation.PSCredential]$Credential,
           [switch]$Active)

    $ps = New-Object Collections.Hashtable($psBoundParameters)
    $ps.Remove('Active') | Out-Null
    # Connect to the VisualCron server
    $server = Get-VCServer @ps
#Write-Output $server
    #
    # Get all the jobs
    $jobs = Get-AllVCJobs
    Foreach ($job in $jobs)
    {
            $triggers = $job.Triggers # Get the Jobs' Triggers
            Foreach ($trigger in $triggers)
            {
               if (  $job.stats.active -eq $true -And $trigger.TriggerType -eq "EventType" -And $trigger.Active -eq $false) 
               {
                 Write-Output ("Job Name: " + $job.Name + "	Trigger Desc: " + $trigger.Description )
               }
            }
    }
 
}

SearchTrigs
Support
2021-04-23T13:16:47Z
Gary once again shines with his knowledge and contribution to the community. Thank you!

Armo, let us know if you are still having issues with this.
Michael
Support
http://www.visualcron.com 

Please like  VisualCron on facebook!
Gary_W
2021-04-23T13:31:01Z
Thanks for the kind words Michael, I'm only happy to give back what I've received here 🙂 We're all in this together!
Similar Topics
Users browsing this topic
Scroll to Top