Forum Discussion
How to monitor the existing of a file on an azure vm with azure tools
May leverage Azure monitor and PowerShell:
SAMPLE [Please make sure you are fully understand the script before apply]
$FilePath = "C:\xxxx\file.txt"
$LastWriteTime = (Get-Item $FilePath).LastWriteTime
$CurrentTime = Get-Date
$TimeDifference = $CurrentTime - $LastWriteTime
if (Test-Path $FilePath -and $TimeDifference.TotalMinutes -le 20) {
Write-Output "File exists and was updated in the last 20 minutes."
# Trigger an alert or take action
} else {
Write-Output "File does not exist or was not updated in the last 20 minutes."
}
- Gr1n3Sep 11, 2024Copper Contributor
Kidd_Ip thank you for your reply!
I wasn't asking for a powershell script as I have a similar one doing the job perfectly for the on-premise servers. However, I want to know is there any tool or way to do the same with azure tools (monitor, app insights, or any other one) as I'm new to this, and if it's possible a way to re-use the scripts I'm using for my on premises monitoring.
Thanks