Link to home
Start Free TrialLog in
Avatar of alanlam123
alanlam123

asked on

How to write the DCDIAG powershell

Hi expert

How to write a  Dcdiag script and send email and report about all servers in Forest
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Check out this script in the ScriptCenter at Microsoft:  https://gallery.technet.microsoft.com/scriptcenter/Active-Directory-Health-709336cd

Dan
Avatar of alanlam123
alanlam123

ASKER

Hi Expert

Please comment the following and do i miss out the anything?

#DcDiag script to send email report about all servers in Forest#


$users = "alan.lam@zuji.com"
$fromemail = "alan.lam@zuji.com"
$server = "mail.webjet.co.sg"
$subject = "DC Diag Report for all DCs - $ ((Get-Date).ToShortDateString())"
Get-ADDomainController -Filter * | ForEach-Object {
$DCDiag = DcDiag /a /s:$($_.Hostname)
$email =@{

From = $fromemail
To = $users
Subject = $subject
SMTPServer = $server
Boday = ($DCDiag | Out-String)
}
Send-MailMessage @email
}
Why not use the script that is the focus of that link I posted?  It is already to go, you just need to check the email info?

Also, this email would be quite long and user/reader unfriendly.

In your array, "Boday" should be "Body".

I recommend using the script in the link provided above.

Dan
Thanks it really works the only issue that i have that not able to send email to my inbox.

cheers
If you were to explain, in more detail, the errors sending the email is causing, I am sure it can be resolved.

Dan
There is no error and let me show you the following;

$reportpath = ".\ADReport.htm"

if((test-path $reportpath) -like $false)
{
new-item $reportpath -type file
}
$smtphost = "mail.webjet.co.au"
$from = "alan.lam@zuji.com"
$email1 = "alan.lam@zuji.com"
$timeout = "60"
ASKER CERTIFIED SOLUTION
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nil