$file = New-Item -Path $filePath -ItemType "file" -ErrorAction:Stop
Add-Content -Path $filePath -Value $html -ErrorAction:Stop
Write-Host "Report path: " $filePath
}
catch
{
Write-Host "Report writing failed, .html report will not be written to output folder. You can find it below."
Write-Host
Write-Host $resultHtml
}
}
else
{
Write-Host "Output folder is invalid. Html report will not be written to output folder"
}
}
# very dirty trick - remove in next version by passing timeout into script
if ($taskName -eq 'Microsoft.Windows.DNSServer.2016.Task.HealthCheck.ConfiguredRootHints')
{
$calcTimeout = $targets.Count * 1000
$overrides.Add("TimeoutSeconds",$calcTimeout.ToString())
}
else
{
$calcTimeout = 250
}
if($OutputFolder -eq $null -or $OutputFolder -eq "")
{
# here we do not remove linebreaks
$xml = [xml]($taskResult.Output)
if($xml.DataItem.StdOut.InnerText -ne $null)
{
$str = $xml.DataItem.StdOut.InnerText
$str = $str.Replace("&amp;lt;","<")
$str = $str.Replace("&amp;gt;",">")
$str = $str.Replace("&lt;","<")
$str = $str.Replace("&gt;",">")
$resultHtml = $str
}
else
{
Write-Host "There are no Task Output"
}
#Write-Host "OutputFolder parameter is not specified, task report will not be written."
Write-Host $resultHtml
}
else
{
$xml = [xml]($taskResult.Output)
if($xml.DataItem.StdOut.InnerText -ne $null)
{
$str = $xml.DataItem.StdOut.InnerText
$str = $str.Replace("`n","");
$str = $str.Replace("`r","");
$str = $str.Replace("&amp;lt;","<")
$str = $str.Replace("&amp;gt;",">")
$str = $str.Replace("&lt;","<")
$str = $str.Replace("&gt;",">")
$resultHtml = $str
}
else
{
Write-Host "There are no Task Output"
}
Write-Host "OutputFolder: " $OutputFolder
try
{
Save-TaskHtmlReport -path $OutputFolder -reportName $ReportName -html $resultHtml
}
catch
{
Write-Host "Report writing failed, .html report will not be written to output folder. You can find it below."
Write-Host
Write-Host $resultHtml
}
}
}
else
{
if($taskResult.Status -eq [Microsoft.EnterpriseManagement.Runtime.TaskStatus]::Started)
{
Write-Host "Remote task was timed out. Report will not be written to output folder."
}
else
{
$res = $taskResult.Status
Write-Host "Remote task failed with status " $res
}
}
}
else
{
Write-Host 'No objects to perform complex tasks. Computer with DNS Server role required.'
}
$SCOMPowerShellKey = "HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Powershell\V2"
$SCOMModulePath = (Get-ItemProperty $SCOMPowerShellKey).InstallDirectory
if ($true -eq [string]::IsNullOrEmpty($SCOMModulePath))
{
$ErrorMessage = "Path to SCOM cmdlets not found in registry."
Write-Host $ErrorMessage
exit
}
#
# Tests whether given DNS Server is able to resolve input DNS Name.
#
Function Test-DnsServerForInputDnsName
{
param (
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$dnsName,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$dnsServer,
$rrType = "All"
)
$result = [RetStatus]::Failure;
try {
$retObj = ExecuteCmdLet "Resolve-DnsName" @{"Name" = $dnsName; "Type" = $rrType; "Server" = $dnsServer};
if ($null -eq $retObj) {
LogComment $("Resolve-DnsName for " + $dnsName + " failed on server " + $dnsServer + " with " + $script:cmdLetReturnedStatus) $script:logLevel.Error;
$result = $script:cmdLetReturnedStatus;
} else {
LogComment $("Name resolution of " + $dnsName + " passed on server " + $dnsServer);
$result = [RetStatus]::Success;
}
$dnsServerIP = $null;
if (![Net.IPaddress]::TryParse($dnsServer, [ref]$dnsServerIP)) {
try {
#Resolve and get first IP
$dnsServerIP = [System.Net.Dns]::GetHostAddresses($dnsServer).IPAddressToString.Split(" ")[0];
} catch {
LogComment $("Exception while trying to get IP Address of " + $dnsServer + "`n" + $_.Exception) $script:logLevel.Error;
throw;
}
}
$retObj = ExecuteCmdLet "Test-DnsServer" @{"ComputerName" = $remoteServer; "ZoneName" = $zoneName; "IPAddress" = $dnsServerIP};
if ($null -eq $retObj) {
LogComment $("Test-DnsServer failed for " + $zoneName + " on server " + $dnsServer) $script:logLevel.Warning;
$result = $script:cmdLetReturnedStatus;
} else {
if (($retObj.Result -eq "Success") -or ($retObj.Result -eq "NotAuthoritativeForZone")) {
LogComment $("Test-DnsServer passed for " + $zoneName + " on server " + $dnsServer + " with Result: " + $retObj.Result);
$result = [RetStatus]::Success;
} else {
LogComment $("Test-DnsServer failed for " + $zoneName + " on server " + $dnsServer + " with Result: " + $retObj.Result) $script:logLevel.Warning;
$result = $retObj.Result;
}
}
} catch {
LogComment $("Test-DnsServerForInputDnsName failed " + $_.Exception) $script:logLevel.Error;
$result = [RetStatus]::Failure;
}