A user asked for help creating a trigger which compares two PVS stores and sends an email if not identical. @member suggested ChatGPT, which can add an error to the event log if the contents are not the same, and a second trigger can be set up for the error. A PowerShell script was provided which writes an error message to the event log if changes are present in the folders, with the needed event log name, source, and EventId customizable.
Read the entire ‘Creating a Trigger to Compare Two PVS Stores’ thread below:
Hi all, I would like to create a trigger which compares both PVS Stores and sends an email if they are not identical = admin forgot to copy the vdisk from A to B. Any ideas how I could achieve this?
@member – I bet you have something similar available already ? (to be run as a scheduled trigger)
I don’t have anything but ChatGPT does! 🙂 https://chat.openai.com/share/9bd5926d-14a1-4ecd-9806-1b4edf1fd627
I had it add an error to the event log if the contents are not the same. You can then setup a second trigger on this error and fire an alert.
To write an error to the event log if changes are present in the folders, you can modify the PowerShell script as follows:
“`powershell
Define the paths to the two folders you want to compare
$folder1Path = "C:\Path\To\Folder1"
$folder2Path = "C:\Path\To\Folder2"
Get the list of files and subfolders in each folder
$folder1Contents = Get-ChildItem -Path $folder1Path -File -Recurse
$folder2Contents = Get-ChildItem -Path $folder2Path -File -Recurse
Compare the contents of the two folders
$folder1Only = Compare-Object -ReferenceObject $folder1Contents -DifferenceObject $folder2Contents | Where-Object { $_.SideIndicator -eq "
$folder2Only = Compare-Object -ReferenceObject $folder1Contents -DifferenceObject $folder2Contents | Where-Object { $_.SideIndicator -eq "=>" }
Check if the folders have the same content
if ($folder1Only.Count -eq 0 -and $folder2Only.Count -eq 0) {
Write-Host "Both folders have the same contents."
} else {
Write-Host "Folders have different contents."
# Create an error message
$errorMessage = "Folders $folder1Path and $folder2Path have different contents."
# Write the error message to the event log
Write-EventLog -LogName Application -Source "FolderComparisonScript" -EntryType Error -EventId 1 -Message $errorMessage
# You can replace "Application" with the desired event log name
# "FolderComparisonScript" is used as the source, and you can customize it as needed
# EventId 1 is an example; you can use a different EventId
}
“`
This script will write an error message to the Application event log if changes are present in the folders. You can customize the event log name, source, and EventId as needed. Make sure to replace $folder1Path and $folder2Path with the actual folder paths you want to compare.
Continue reading and comment on the thread ‘Creating a Trigger to Compare Two PVS Stores in ControlUp’. Not a member? Join Here!
Categories: All Archives, ControlUp Scripts & Triggers