How to monitor the existing of a file on an azure vm with azure tools

Copper Contributor

Greetings,

I need to monitor whether a file exist or is updated in the last 20 minutes located in an azure vm with azure tools. If one of these two conditions are met an alert is fired.

Currently, I'm able to do so with powershell for my on-premesise servers, however we are migrating to azure monitor and wonder if there is a tool or a way where I can do it from azure.

PS: will be very helpful and appreciated if I can re-use my powershell scripts 🙂

Thanks

2 Replies

@Gr1n3 

 

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."
}

@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