Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

need assistance with powershell script

Posted on 2014-12-25
9
Medium Priority
?
264 Views
Last Modified: 2014-12-25
hello, I'm trying to get this script on TechNet to work, can someone take a look?

the script runs but the replication report is not working, all I see in the replication section is *32

here is the link on TechNet:
https://gallery.technet.microsoft.com/AD-Daily-Health-Check-3d0932db/view/Discussions#content

here is  the script:
Function Getservicestatus($service, $server)
{
	$st = Get-service -computername $server | where-object { $_.name -eq $service }
	if($st)
	{$servicestatus= $st.status}
	else
	{$servicestatus = "Not found"}
	
	Return $servicestatus
}

$Forest = [system.directoryservices.activedirectory.Forest]::GetCurrentForest()

[string[]]$computername = $Forest.domains | ForEach-Object {$_.DomainControllers} | ForEach-Object {$_.Name} 


$report1= @()
foreach ($server in $computername){
$temp1 = "" | select server, pingstatus
if ( Test-Connection -ComputerName $server -Count 1 -ErrorAction SilentlyContinue ) {
$temp1.pingstatus = "Pinging"
}
else {
$temp1.pingstatus = "Not pinging"
}
$temp1.server = $server
$report1+=$temp1
}

$b = $report1 | select server, pingstatus  | ConvertTo-HTML -Fragment -As Table -PreContent "<h2>Server Availability</h2>" | Out-String


$report = @()

foreach ($server in $computername){
$temp = "" | select server, NTDS, DNS, DFSR, netlogon, w32Time
$temp.server = $server

$temp.NTDS = Getservicestatus -service "NTDS" -server $server
$temp.DNS = Getservicestatus -service "DNS" -server $server
$temp.DFSR = Getservicestatus -service "DFSR" -server $server
$temp.netlogon = Getservicestatus -service "netlogon" -server $server
$temp.w32Time = Getservicestatus -service "w32Time" -server $server
$report+=$temp
}

$b+= $REPORT | select server, NTDS, DNS, DFSR, netlogon, w32Time | ConvertTo-HTML -Fragment -As Table -PreContent "<h2>Service Status</h2>" | Out-String


add-type -AssemblyName microsoft.visualbasic 
$strings = "microsoft.visualbasic.strings" -as [type] 


$report = @()
foreach ($server in $computername){
$temp = "" | select server, SysvolTest
$temp.server = $server
$svt = dcdiag /test:netlogons /s:$server
if($strings::instr($svt, "passed test NetLogons")){$temp.SysvolTest = "Passed"}
else
{$temp.SysvolTest = "Failed"}
$report+=$temp
}
$b+= $REPORT | select server, SysvolTest | ConvertTo-HTML -Fragment -As Table -PreContent "<h2>NetLogon Test</h2>" | Out-String



$workfile = repadmin.exe /showrepl * /csv 
$results = ConvertFrom-Csv -InputObject $workfile | where {$_.'Number of Failures' -ge 1}
 
 
$results = $results | where {$_.'Number of Failures' -gt 1 }
 
if ($results -ne $null ) {
    $results = $results | select "Source DSA", "Naming Context", "Destination DSA" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status"
    $b+= $results | select "Source DSA", "Naming Context", "Destination DSA" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status" | ConvertTo-HTML -Fragment -As Table -PreContent "<h2>Replication Status</h2>" | Out-String    

} else {
    $results = "There were no Replication Errors"
    $b+= $results | ConvertTo-HTML -Fragment  -PreContent "<h2>Replication Status</h2>" | Out-String
     
}




$head = @'
<style>
body { background-color:#dddddd;
       font-family:Tahoma;
       font-size:12pt; }
td, th { border:1px solid black; 
         border-collapse:collapse; }
th { color:white;
     background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }
</style>
'@
 
$s = ConvertTo-HTML -head $head -PostContent $b -Body "<h1>Active Directory Checklist</h1>" | Out-string


$emailFrom = "Itsupport01@examplexxyy.com" 
$emailTo = "SD@ssyyhe.com"

$smtpserver= "xxx.local" 
$smtp=new-object Net.Mail.SmtpClient($smtpServer)

$msg = new-object Net.Mail.MailMessage
$msg.From = $emailFrom
$msg.To.Add($emailTo)
$msg.IsBodyHTML = $true
$msg.subject="Active Directory Health Check Report" 
$msg.Body = $s
$smtp.Send($msg)

Open in new window

0
Comment
Question by:siber1
  • 5
  • 4
9 Comments
 
LVL 71

Expert Comment

by:Qlemo
ID: 40517671
Do you mean this part?
$workfile = repadmin.exe /showrepl * /csv 
$results = ConvertFrom-Csv -InputObject $workfile | where {$_.'Number of Failures' -ge 1}
 
 
$results = $results | where {$_.'Number of Failures' -gt 1 }
 
if ($results -ne $null ) {
    $results = $results | select "Source DSA", "Naming Context", "Destination DSA" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status"
    $b+= $results | select "Source DSA", "Naming Context", "Destination DSA" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status" | ConvertTo-HTML -Fragment -As Table -PreContent "<h2>Replication Status</h2>" | Out-String    

} else {
    $results = "There were no Replication Errors"
    $b+= $results | ConvertTo-HTML -Fragment  -PreContent "<h2>Replication Status</h2>" | Out-String
     
}

Open in new window

I cannot see how this should result in "*32". Please test that part only.
0
 

Author Comment

by:siber1
ID: 40517686
Hi Qlemo, where would the output file be? I just ran that subset of code and it seemed to run but I don't see the output file to verify.

thx
0
 

Author Comment

by:siber1
ID: 40517721
hi Qlemo, are you still there? really appreciate your assistance with this, I ran the subset you requested, but it didn't produce any output file that I could share with you.  pls advise I'd really like to get this working.   thx
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 71

Expert Comment

by:Qlemo
ID: 40517724
You can just type $b or $results (one of both)  to check the output.
0
 

Author Comment

by:siber1
ID: 40517735
when I type $b or $results - it does not return any results.  [empty]   thx
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40517844
So there is at most 1 replication failure. That part only starts reporting if more than one failure occurred.
This leads to the question, which part exactly should not work.  *32 is something I only met in Task Manager, for 32 bit applications on x64 systems.
0
 

Author Comment

by:siber1
ID: 40517854
should there not be a summary section for "replication status"?

I see a summary on the other sections, but for Replication summary here is what I see in the report:

*
32

thx - S.
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40517958
You are right, the HTML output is as stated and wrong, but both $b and $results are not empty. $results is correct "There were no Replication Errors", but the HMTL output is wrong (number of characters instead of the string itself). This is a common mistake, and I didn't spot it earlier either.

Here is corrected and slightly reworked code (for the replication report only), as there was superfluous operations,
$workfile = repadmin.exe /showrepl * /csv 
$results = ConvertFrom-Csv -InputObject $workfile | where {$_.'Number of Failures' -ge 1}
 
if ($results -ne $null ) {
    $b+= $results | select "Source DSA", "Naming Context", "Destination DSA" ,"Number of Failures", "Last Failure Time", "Last Success Time", "Last Failure Status" | ConvertTo-HTML -Fragment -As Table -PreContent "<h2>Replication Status</h2>" | Out-String    

} else {
    $b+= "<h2>Replication Status</h2><br>There were no Replication Errors<br><br>"
}

Open in new window

0
 

Author Closing Comment

by:siber1
ID: 40517992
thank you Qlemo, that resolved the issue. brilliant as always.

S.
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Steps to fix “Unable to mount database. (hr=0x80004005, ec=1108)”.
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
This video discusses moving either the default database or any database to a new volume.
Loops Section Overview

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question