Critical Scopes Availability

Microsoft.Windows.DHCPServer.10.0.Tasks.GetAllCriticalScopes (Task)

Provides HTML report of all Critical Scopes and addresses availability percentage

Element properties:

TargetMicrosoft.Windows.DHCPServer.10.0.IPv4ScopesRuntime
AccessibilityInternal
CategoryCustom
EnabledTrue
RemotableFalse
Timeout300

Member Modules:

ID Module Type TypeId RunAs 
PA ProbeAction Microsoft.Windows.DHCPServer.10.0.HtmlReportePowershellProbe System.PrivilegedMonitoringAccount

Source Code:

<Task ID="Microsoft.Windows.DHCPServer.10.0.Tasks.GetAllCriticalScopes" Accessibility="Internal" Target="Microsoft.Windows.DHCPServer.10.0.IPv4ScopesRuntime" Enabled="true" Timeout="300" Remotable="true">
<Category>Custom</Category>
<ProbeAction ID="PA" TypeID="Microsoft.Windows.DHCPServer.10.0.HtmlReportePowershellProbe" RunAs="System!System.PrivilegedMonitoringAccount">
<ScriptName>Microsoft.Windows.Server.10.0.GetCriticalScopes.Script.ps1</ScriptName>
<ScriptBody><Script>

param ([double] $ErrorThreshold,[string] $OutputServer,[string] $OutputFolder)
$SCRIPT_NAME = "Microsoft.Windows.Server.10.0.GetCriticalScopes.Script"
$ErrorActionPreference = "Stop"
$Error.Clear()
try
{
if([string]::IsNullOrEmpty($OutputServer))
{
$OutputServer= hostname
}
if(!(test-connection -ComputerName $OutputServer -quiet))
{
Write-Warning "Verify that the computer exists on the network and that the name provided is spelled correctly."
Exit
}
$IPV4Scopes = Get-DhcpServerv4ScopeStatistics
$SourceServer = hostname
$Html="&lt;Html&gt;&lt;Title&gt;DHCP Available Scope Addresses Report&lt;/Title&gt;&lt;Body&gt;&lt;H1&gt;DHCP Available Scope Addresses Report for $SourceServer computer&lt;/H1&gt;"

$CriticalScopesCount=0

if($IPV4Scopes -eq $null)
{
$IPV4ScopesCount = 0
}
else
{
if($IPV4Scopes.Count -eq $null)
{
$IPV4ScopesCount = 1
}
else
{
$IPV4ScopesCount = $IPV4Scopes.Count
}
}


$Html= $Html + "&lt;Table border='1'&gt;&lt;tr&gt;&lt;th&gt;S No&lt;/th&gt;&lt;th&gt;Scope ID&lt;/th&gt;&lt;th&gt;% free Scope Addresses&lt;/th&gt;&lt;/tr&gt;"

for ($itmIPV4Scope=1; $itmIPV4Scope -le $IPV4ScopesCount; $itmIPV4Scope++)
{

if($IPV4ScopesCount -eq 1)
{
$ObjIPV4Scope = $IPV4Scopes
}
else
{
if($IPV4Scopes.Get($itmIPV4Scope-1) -ne $null)
{
$ObjIPV4Scope = $IPV4Scopes.Get($itmIPV4Scope-1)
}
}

$PercIPV4InUse = $ObjIPV4Scope.PercentageInUse
$PercIPV4Avail = 100-$PercIPV4InUse


if($PercIPV4Avail -le $ErrorThreshold)
{
$tbData=$ObjIPV4Scope.ScopeId.toString()
$Html= $Html + "&lt;tr&gt;&lt;td&gt; $itmIPV4Scope &lt;/td&gt;&lt;td&gt; $tbData &lt;/td&gt;&lt;td&gt; $PercIPV4Avail &lt;/td&gt;&lt;/tr&gt;"
$CriticalScopesCount++
}
}
$Html= $Html + "&lt;/Table&gt;&lt;br&gt; $CriticalScopesCount Scopes have available Scopes below Threshold value&lt;/br&gt;&lt;/Body&gt;&lt;/Html&gt;"


$ScriptBlock = {
$date=Get-Date
$FileName="DHCP.Available.Scope.Addresses.Report_"+$date.ToString("dd-MM-yyyy_HH-mm-ss.ff")+".html"
$FilePath=$args[1]+"\"+$FileName
$args[0] | Out-File -filepath $FilePath
}

$result = Invoke-Command -ComputerName $OutputServer -ScriptBlock $ScriptBlock -ArgumentList $Html,$OutputFolder

Write-Host "$CriticalScopesCount Scopes have available Scopes below Threshold value"
}
catch [System.Management.Automation.Remoting.PSRemotingTransportException]
{
Write-Warning "Access Denied : Please provide authorised username and password"
}
catch [System.Exception]
{
if($error[0].exception.gettype().fullname -eq "System.Management.Automation.Remoting.PSRemotingTransportException")
{
Write-Warning "Access Denied : Please provide authorised username and password"
}
else
{
$Description = $_.ToString()
Write-Warning $Description
}
}
finally
{
#Write-Host "Script Executed"
}
</Script></ScriptBody>
<ErrorThreshold>10</ErrorThreshold>
<OutputServer/>
<OutputFolder>c:\</OutputFolder>
<TimeoutSeconds>300</TimeoutSeconds>
</ProbeAction>
</Task>