まさお(偽名) さん、こんにちは。
マイクロソフト コミュニティをご利用いただき、ありがとうございます。
PowerShell については一般向けのこのマイクロソフト コミュニティでは情報が集まりにくいかもしれません。
今回の内容であれば、開発者の方々が多く情報交換をされている MSDN フォーラムの Windows PowerShell のカテゴリに投稿してみるとアドバイスが寄せられやすくなると思います。
よければそちらを利用してみてくださいね。
このブラウザーはサポートされなくなりました。
Microsoft Edge にアップグレードすると、最新の機能、セキュリティ更新プログラム、およびテクニカル サポートを利用できます。
PowerShellについては全くの素人です。
あるフォルダを監視して、変更があったら通知するコードをサイトからコピーして改変しました。
VSCode上で実行すると目的通り、フォルダが更新されると通知が来るのですが、ps1ファイルを右クリックで「PowerShellで実行」をすると、エラーは何も出ないのですが、通知も来ません。
なぜだか全くわからないのですが、ご教授頂けますでしょうか。
function ShowToast {
[CmdletBinding()]
PARAM (
[Parameter(Mandatory=$true)][String] $title,
[Parameter(Mandatory=$true)][String] $message,
[Parameter(Mandatory=$true)][String] $detail
)
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
$app_id = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
$content = @"
<?xml version="1.0" encoding="utf-8"?>
<toast scenario="reminder">
<visual>
<binding template="ToastGeneric">
<text>$($title)</text>
<text>$($message)</text>
<text>$($detail)</text>
<image placement="appLogoOverride" hint-crop="circle" hint-align="center" src="画像のパス" />
</binding>
</visual>
<actions>
<input id="snoozeTime" type="selection" defaultInput="15">
<selection id="1" content="1 minute"/>
<selection id="15" content="15 minutes"/>
<selection id="60" content="1 hour"/>
<selection id="240" content="4 hours"/>
<selection id="1440" content="1 day"/>
</input>
<action activationType="system" arguments="snooze" hint-inputId="snoozeTime" content="" />
<action activationType="system" arguments="dismiss" content=""/>
</actions>
</toast>
"@
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($content)
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
}
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "監視するフォルダパス"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$action = {
$path = $Event.SourceEventArgs.FullPath
$FileName = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$msg = "メッセージ"
ShowToast -title "フォルダ監視" -message $msg -detail $changeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "ログ出力先" -value $logline
}
Register-ObjectEvent $watcher "Created" -Action $action
while ($true) {sleep 900}
ロックされた質問。 この質問は、Microsoft サポート コミュニティから移行されました。 役に立つかどうかに投票することはできますが、コメントの追加、質問への返信やフォローはできません。
まさお(偽名) さん、こんにちは。
マイクロソフト コミュニティをご利用いただき、ありがとうございます。
PowerShell については一般向けのこのマイクロソフト コミュニティでは情報が集まりにくいかもしれません。
今回の内容であれば、開発者の方々が多く情報交換をされている MSDN フォーラムの Windows PowerShell のカテゴリに投稿してみるとアドバイスが寄せられやすくなると思います。
よければそちらを利用してみてくださいね。