相关疑难解决方法(0)

Powershell send-mailmessage - 向多个收件人发送电子邮件

我有这个powershell脚本来发送附件的电子邮件,但是当我添加多个收件人时,只有第一个收到邮件.我已经阅读了文档,仍然无法弄明白.谢谢

$recipients = "Marcel <marcel@turie.eu>, Marcelt <marcel@nbs.sk>"

Get-ChildItem "C:\Decrypted\" | Where {-NOT $_.PSIsContainer} | foreach {$_.fullname} |
send-mailmessage -from "primasfrb@nbs.sk" `
            -to "$recipients" `
            -subject "New files" `
            -body "$teloadmin" `
            -BodyAsHtml `
            -priority  High `
            -dno onSuccess, onFailure `
            -smtpServer  192.168.170.61
Run Code Online (Sandbox Code Playgroud)

powershell

52
推荐指数
5
解决办法
20万
查看次数

取消注册已注册的filewatcher事件不起作用

我想用powershell观看一个文件夹,我是PS初学者.

当我启动脚本时,该脚本可以运行一次.

但是当我因为更改了一些脚本代码而不得不重新启动脚本时,我收到以下错误消息:

Cannot subscribe to the specified event. A subscriber with the source identifier 'FileChanged' already exists.
Run Code Online (Sandbox Code Playgroud)

我试过了:

这在脚本的顶部:

Unregister-Event -SourceIdentifier FileChanged
Run Code Online (Sandbox Code Playgroud)

不起作用.

如何正确取消注册事件,以便我可以按照我想要的方式运行脚本并处理先前注册的事件?

$folder = "C:\temp"

$Watcher = New-Object IO.FileSystemWatcher $folder -Property @{ 
    IncludeSubdirectories = $true
    NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
} 

$onChanged = Register-ObjectEvent $Watcher Changed -SourceIdentifier FileChanged -Action {
   $path = $Event.SourceEventArgs.FullPath
   $name = $Event.SourceEventArgs.Name
   $changeType = $Event.SourceEventArgs.ChangeType
   $timeStamp = $Event.TimeGenerated
   Write-Host "The file '$name' was $changeType at $timeStamp"
   Write-Host $path
   #Move-Item $path -Destination $destination -Force …
Run Code Online (Sandbox Code Playgroud)

powershell file-watcher

4
推荐指数
1
解决办法
4172
查看次数

标签 统计

powershell ×2

file-watcher ×1