windows – powershell脚本的电子邮件输出
发布时间:2020-12-14 00:27:44 所属栏目:Windows 来源:网络整理
导读:我找到了这个很棒的脚本,它将当前DFS backlog的状态输出到power shell控制台.这很好用,但我需要脚本给我发电子邮件,所以我可以安排它每晚运行.我已尝试使用Send-MailMessage命令,但无法使其工作.主要是因为我的powershell技能非常弱.我相信大多数问题都围绕
我找到了这个很棒的脚本,它将当前DFS backlog的状态输出到power
shell控制台.这很好用,但我需要脚本给我发电子邮件,所以我可以安排它每晚运行.我已尝试使用Send-MailMessage命令,但无法使其工作.主要是因为我的powershell技能非常弱.我相信大多数问题都围绕着使用Write-Host命令的脚本.虽然着色很好,但我宁愿让它给我发送结果.我还需要能够指定邮件服务器的解决方案,因为dfs服务器没有电子邮件功能.
欢迎和赞赏任何帮助或提示. 这是代码. $RGroups = Get-WmiObject -Namespace "rootMicrosoftDFS" -Query "SELECT * FROM DfsrReplicationGroupConfig" $ComputerName=$env:ComputerName $Succ=0 $Warn=0 $Err=0 foreach ($Group in $RGroups) { $RGFoldersWMIQ = "SELECT * FROM DfsrReplicatedFolderConfig WHERE ReplicationGroupGUID='" + $Group.ReplicationGroupGUID + "'" $RGFolders = Get-WmiObject -Namespace "rootMicrosoftDFS" -Query $RGFoldersWMIQ $RGConnectionsWMIQ = "SELECT * FROM DfsrConnectionConfig WHERE ReplicationGroupGUID='"+ $Group.ReplicationGroupGUID + "'" $RGConnections = Get-WmiObject -Namespace "rootMicrosoftDFS" -Query $RGConnectionsWMIQ foreach ($Connection in $RGConnections) { $ConnectionName = $Connection.PartnerName.Trim() if ($Connection.Enabled -eq $True) { if (((New-Object System.Net.NetworkInformation.ping).send("$ConnectionName")).Status -eq "Success") { foreach ($Folder in $RGFolders) { $RGName = $Group.ReplicationGroupName $RFName = $Folder.ReplicatedFolderName if ($Connection.Inbound -eq $True) { $SendingMember = $ConnectionName $ReceivingMember = $ComputerName $Direction="inbound" } else { $SendingMember = $ComputerName $ReceivingMember = $ConnectionName $Direction="outbound" } $BLCommand = "dfsrdiag Backlog /RGName:'" + $RGName + "' /RFName:'" + $RFName + "' /SendingMember:" + $SendingMember + " /ReceivingMember:" + $ReceivingMember $Backlog = Invoke-Expression -Command $BLCommand $BackLogFilecount = 0 foreach ($item in $Backlog) { if ($item -ilike "*Backlog File count*") { $BacklogFileCount = [int]$Item.Split(":")[1].Trim() } } $Emailbody += "$BacklogFileCount files in backlog $SendingMember->$ReceivingMember for $RGName " } # Closing iterate through all folders } # Closing If replies to ping } # Closing If Connection enabled } # Closing iteration through all connections } # Closing iteration through all groups $emailFrom = "sender@foobar.com" $emailTo = "recipient@foobar.com" $subject = "DFS Backlog Report" $smtpServer = "MailServer" $smtp = new-object Net.Mail.SmtpClient($smtpServer) $smtp.Send($emailFrom,$emailTo,$subject,$Emailbody)
如果你想分支出PowerShell,你可以将脚本的输出重定向到文本文件并使用第三方命令行邮件程序如blat将文本文件作为电子邮件的正文(或附件)发送并指定smtp服务器反弹.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- active-directory – 使用DSMOD解锁AD用户帐户(命令行)
- 如何在Windows Server 2008中检测C#中的防病毒?
- active-directory – 从2008迁移到2012R2域后无法看到AD
- Windows – Docker Machine无法使用hyperv成功访问ip地址/机
- windows-7 – Windows 7中是否支持ITaskScheduler?
- windows – 批处理文件中的换行符
- 有没有API可以在Windows上预先检索受信任的根证书列表?
- windows-server-2008 – Microsoft Windows等同于LXC
- 在Windows Server 2008上设置Mercurial时出错
- 在Windows上使用SQLite和C.
推荐文章
站长推荐
热点阅读