From b6f36c62a08eb208442ce4526480764ff70fedb3 Mon Sep 17 00:00:00 2001 From: "jonas@geiger-natur.de" Date: Sat, 4 Jan 2025 21:43:21 +0100 Subject: [PATCH] Windows notification --- DownloadsFileSync.ps1 | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/DownloadsFileSync.ps1 b/DownloadsFileSync.ps1 index 0292df6..f70d2ec 100644 --- a/DownloadsFileSync.ps1 +++ b/DownloadsFileSync.ps1 @@ -1,11 +1,12 @@ -$sourcePath = "C:\Users\YourUsername\Downloads" -$destinationPath = "\\YourServer\YourShare" +$sourcePath = "C:\Users\jonas\Downloads" +$destinationPath = "\\synology-ds720\DS720\Software" $fileExtensions = @("exe", "msi", "iso", "img") $pattern = "[A-Za-z]+" -$timeSpan = New-TimeSpan -Minutes 600 +$timeSpan = New-TimeSpan -Seconds 600 while ($true) { $now = Get-Date + $counter = 0 $files = Get-ChildItem -Path $sourcePath -File | Where-Object { $_.LastWriteTime -gt $now.Subtract($timeSpan) -and @@ -35,7 +36,30 @@ while ($true) { } Copy-Item -Path $file.FullName -Destination "$($destFolder)\$($now.ToString("yyyy-MM-dd"))_$($file.Name)" -Force + $counter++ } - Start-Sleep -Seconds 600 + + #NOTIFICATION + [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null + $template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02) + + $toastXml = [xml] $template.GetXml() + $toastXml.GetElementsByTagName("text").Item(0).AppendChild($toastXml.CreateTextNode("Files synchronized")) > $null + $toastXml.GetElementsByTagName("text").Item(1).AppendChild($toastXml.CreateTextNode("$($counter) of $($files.Count)")) > $null + + $xml = New-Object Windows.Data.Xml.Dom.XmlDocument + $xml.LoadXml($toastXml.OuterXml) + + $toast = [Windows.UI.Notifications.ToastNotification]::new($xml) + $toast.Tag = "DownloadsFileSync" + $toast.Group = "DownloadsFileSync" + $toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1) + + $notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("DownloadsFileSync") + $notifier.Show($toast); + + + #START-SLEEP + Start-Sleep -Seconds $timeSpan.TotalSeconds } \ No newline at end of file