Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $FilePath = ""
- $BotToken = ""
- $ChatID = ""
- # Переменные
- $LastAccessTime = (Get-Item $FilePath).LastAccessTime
- $LastWriteTime = (Get-Item $FilePath).LastWriteTime
- $FileExists = Test-Path $FilePath
- # Основной цикл
- while ($true) {
- Start-Sleep -Seconds 5
- $CurrentExists = Test-Path $FilePath
- if ($CurrentExists) {
- $CurrentAccessTime = (Get-Item $FilePath).LastAccessTime
- $CurrentWriteTime = (Get-Item $FilePath).LastWriteTime
- if ($CurrentAccessTime -ne $LastAccessTime) {
- $LastAccessTime = $CurrentAccessTime
- $msg = "File open: `"$FilePath`" в $CurrentAccessTime"
- Invoke-RestMethod -Uri "https://api.telegram.org/bot$BotToken/sendMessage" `
- -Method POST -Body @{
- chat_id = $ChatID
- text = $msg
- parse_mode = "Markdown"
- }
- }
- if ($CurrentWriteTime -ne $LastWriteTime) {
- $LastWriteTime = $CurrentWriteTime
- $msg = "File modified: `"$FilePath`" в $CurrentWriteTime"
- Invoke-RestMethod -Uri "https://api.telegram.org/bot$BotToken/sendMessage" `
- -Method POST -Body @{
- chat_id = $ChatID
- text = $msg
- parse_mode = "Markdown"
- }
- }
- } elseif ($FileExists) {
- $FileExists = $false
- $msg = "File deleted: `"$FilePath`""
- Invoke-RestMethod -Uri "https://api.telegram.org/bot$BotToken/sendMessage" `
- -Method POST -Body @{
- chat_id = $ChatID
- text = $msg
- parse_mode = "Markdown"
- }
- } elseif (-not $FileExists -and $CurrentExists) {
- $FileExists = $true
- $LastAccessTime = (Get-Item $FilePath).LastAccessTime
- $LastWriteTime = (Get-Item $FilePath).LastWriteTime
- $msg = "File restored: `"$FilePath`""
- Invoke-RestMethod -Uri "https://api.telegram.org/bot$BotToken/sendMessage" `
- -Method POST -Body @{
- chat_id = $ChatID
- text = $msg
- parse_mode = "Markdown"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment