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()