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


Robert Goodman
2024-06-24T16:24:09Z
Hello,

Basically, what the title is. I saw one post about using ObjectFinder.FindObject in .NET but I'm not able to find anything similar in PowerShell.

I know I can return all the jobs from the server using server.Jobs.GetAll(), but I'd like to look through every object, not just Jobs.

Sponsor
Forum information
thomas
2024-06-25T07:08:36Z
ChatGPT knows a decent amount about the VC api. It came up with some code when i asked you question (In version 4o). Have you tried it?
Robert Goodman
2024-06-25T16:51:03Z
Hi thomas,

I really appreciate the reply. I did try it, but it only searched the description and the name of Jobs and Tasks. It is a good start, but I wanted to look further. For example, if the Source and/or Destination in a Copy Job uses the value I'm looking for.

As I understand it, for each Task type I'd have to look in a different spot.

Do you have any suggestions for a good prompt in ChatGPT to help get the most out of it for VisualCron?

Thank you.
Robert Goodman
2024-06-25T18:13:13Z
I went back and tried again. I had to ask it to go through all the properties and I think it is still only doing the properties of each job and task, which is where probably most of that data will be found. I'm not sure if it would also go through Notifications, Variables, Credentials, etc. I might have to do those separately.

I still need to go through this code carefully, but I thought it might be useful to others:

Robert Goodman
2024-06-25T18:15:11Z
The code didn't get posted. Trying again:

# Load the VisualCron Client DLL
Add-Type -Path "C:\Path\To\VisualCronAPI.dll"

# Initialize VisualCron API Client
$vcHost = "your-visualcron-server"
$vcPort = 16444 # Default port
$vcUsername = "your_username"
$vcPassword = "your_password"

# Create a new instance of the Client class
$vcClient = New-Object VisualCron.VCClient($vcHost, $vcPort)

# Authenticate with VisualCron
$vcClient.Login($vcUsername, $vcPassword)

# Function to search all properties of VisualCron objects
function Search-VCObjects {
param (
[string]$searchValue
)

# Retrieve all jobs
$jobs = $vcClient.Jobs.GetAll()

# Initialize arrays to store matching jobs and tasks
$matchingJobs = @()
$matchingTasks = @()

# Helper function to search all properties of an object
function Search-AllProperties {
param (
[object]$obj,
[string]$searchValue
)
$properties = $obj | Get-Member -MemberType Properties
foreach ($prop in $properties) {
$propValue = $obj."$($prop.Name)"
if ($propValue -like "*$searchValue*") {
return [PSCustomObject]@{
PropertyName = $prop.Name
PropertyValue = $propValue
}
}
}
return $null
}

# Filter jobs and their tasks based on the search value
foreach ($job in $jobs) {
$jobMatch = Search-AllProperties -obj $job -searchValue $searchValue
if ($jobMatch) {
$matchingJobs += [PSCustomObject]@{
JobName = $job.Name
JobDescription = $job.Description
PropertyName = $jobMatch.PropertyName
PropertyValue = $jobMatch.PropertyValue
}
}

# Iterate over tasks in the job
foreach ($task in $job.Tasks) {
$taskMatch = Search-AllProperties -obj $task -searchValue $searchValue
if ($taskMatch) {
$matchingTasks += [PSCustomObject]@{
JobName = $job.Name
TaskName = $task.Name
TaskDescription = $task.Description
PropertyName = $taskMatch.PropertyName
PropertyValue = $taskMatch.PropertyValue
}
}
}
}

return [PSCustomObject]@{
Jobs = $matchingJobs
Tasks = $matchingTasks
}
}

# Execute the search
$searchValue = "value_to_search"
$searchResults = Search-VCObjects -searchValue $searchValue

# Output the results
$searchResults.Jobs | ForEach-Object {
Write-Output "Job found: Name = $($_.JobName), Description = $($_.JobDescription), Property = $($_.PropertyName), Value = $($_.PropertyValue)"
}

$searchResults.Tasks | ForEach-Object {
Write-Output "Task found in Job $($_.JobName): Name = $($_.TaskName), Description = $($_.TaskDescription), Property = $($_.PropertyName), Value = $($_.PropertyValue)"
}

# Logout from VisualCron
$vcClient.Logout()
thomas
2024-06-26T06:33:40Z
My ps skills are not great so cannot help there sorry. There are some powershell heros on this forum, hopefully they can help you
Scroll to Top