I rarely use PowerShell and I have been hacking away at a script to check our AD health for our domain. I am getting the desired information but I am struggling with the email being sent not formatted/aligned better. Perhaps someone might have a suggestion or point me in a better direction?<\/p>\n
Here you can see the current script, and the results below. The email looks worse than the result posted here, so I have attached a snippet for your viewing pleasure.<\/p>\n
$myRepInfo = @(repadmin /replsum * /bysrc /bydest /sort:delta)\n$smtpServer = \"smtpserver.domain.com\"\n$svcs = \"ADws\",\"DNS\",\"DFSR\",\"Kdc\",\"IsmServ\"\n\n$msg = new-object Net.Mail.MailMessage\n$smtp = new-object Net.Mail.SmtpClient($smtpServer)\n\n$msg.From = [email protected]\n$msg.To.Add([email protected])\n$msg.Subject = \"AD Replication Report \" + [System.DateTime]::Now\n\n$dcs = \"SRVR1\",\"SRVR2\",\"SRVR3\"\n$svcs = \"ADws\",\"DNS\",\"DFSR\",\"Kdc\",\"IsmServ\"\n\nforeach ($server in $dcs) {\n\n $msg.body += Get-Service -Name $svcs -ComputerName $server | Select-Object MachineName, Name, Status, DisplayName | Out-String \n\n}\n\n$msg.body += $myRepInfo | Where-Object { $_ } | ForEach-Object { $_ -replace $_,\"$_`n\" }\n$msg.body += $myServices\n\n$smtp.Send($msg)\n\n<\/code><\/pre>\n
Advertisement
MachineName Name Status DisplayName<\/p>\n
\nSRVR3 ADws Running Active Directory Web Services<\/p>\n
SRVR3 DFSR Running DFS Replication<\/p>\n
SRVR3 DNS Running DNS Server<\/p>\n
SRVR3 IsmServ Running Intersite Messaging<\/p>\n
SRVR3 Kdc Running Kerberos Key Distribution Center<\/p>\n
MachineName Name Status DisplayName<\/p>\n
\nSRVR2 ADws Running Active Directory Web Services<\/p>\n
SRVR2 DFSR Running DFS Replication<\/p>\n
SRVR2 DNS Running DNS Server<\/p>\n
SRVR2 IsmServ Running Intersite Messaging<\/p>\n
SRVR2 Kdc Running Kerberos Key Distribution Center<\/p>\n
MachineName Name Status DisplayName<\/p>\n
\nSRVR1 ADws Running Active Directory Web Services<\/p>\n
SRVR1 DFSR Running DFS Replication<\/p>\n
SRVR1 DNS Running DNS Server<\/p>\n
SRVR1 IsmServ Running Intersite Messaging<\/p>\n
SRVR1 Kdc Running Kerberos Key Distribution Center<\/p>\n
Replication Summary Start Time: 2022-11-15 16:14:45 Beginning data collection for replication summary, this may take awhile:<\/p>\n
…<\/p>\n
Source DSA largest delta fails/total %% error<\/p>\n
SRVR3 26m:11s 0 / 10 0<\/p>\n
SRVR1 26m:11s 0 / 10 0<\/p>\n
SRVR2 25m:35s 0 / 10 0<\/p>\n
Destination DSA largest delta fails/total %% error<\/p>\n
SRVR2 26m:11s 0 / 10 0<\/p>\n
SRVR3 25m:35s 0 / 10 0<\/p>\n
SRVR1 23m:29s 0 / 10 0<\/p>\n
<\/p>\n
Thanks for taking a look!<\/p>\n
Chuck<\/p>","upvoteCount":7,"answerCount":5,"datePublished":"2022-11-16T15:50:00.000Z","author":{"@type":"Person","name":"charles19","url":"https://community.spiceworks.com/u/charles19"},"acceptedAnswer":{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n