DNS scavenging_status


$zones = Get-Content “C:\Users\k054995\Desktop\test\input.txt”

foreach($zone in $zones)

{

$Output = Get-DnsServerZoneAging -Name $zone -ComputerName pgc2eu-dceu101 | Select-Object ZoneName,AgingEnabled,RefreshInterval,NoRefreshInterval

$Output

$Output | export-csv -Path “C:\Users\k054995\Desktop\test\eu1_reverse-lookupzone_scavenging_status.csv” -NoTypeInformation -Append

}

Advertisements

AD replication Test


#identify AD sites which differ in replication schedule from a reference site, here GC1

$RefscheduleRaw= ((Get-ADReplicationSite -Identity GC1).ReplicationSchedule.RawSchedule)
$Refschedule= ((Get-ADReplicationSite -Identity GC1).ReplicationSchedule)

#Set-ADReplicationSite -Identity test -ReplicationSchedule $Refschedule

$sites= (Get-ADForest).sites
$SiteList= @(”)

foreach($site in $sites){
$schedule= ”
$schedule= ((Get-ADReplicationSite -Identity $site).ReplicationSchedule.RawSchedule)
if(!$schedule -or ($schedule -ne $RefscheduleRaw)){
$SiteList+=$site
# $site
}

}

$siteList |Sort-Object

Powershell Get-PSADForestInfo


https://github.com/PyroTek3/PowerShell-AD-Recon/blob/master/Get-PSADForestInfo

$ADForestInfo = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Schema

DHCP pool monitor


#DHCP Percent of Addresses Remaining Threshold

$DHCPLowPercentThreshold = 10

#From Email Address

$FromAddress = “dhcpalert@domain.com”

#To Email Address

$ToAddress = “user@domain.com”

#SMTP Server Address

$SmtpServerAddress = “mail.domain.com”

 

$5MinutesAgo = [DateTime]::Now.AddMinutes(-5)

$DHCPLowEvent = @(Get-EventLog -LogName “System” -After $5MinutesAgo -InstanceID 1020)[0]

$DHCPLowEventMessage = $DHCPLowEvent.Message

$DHCPLowPercent = 100 – $DHCPLowEvent.ReplacementStrings[1]

If ($DHCPLowPercent -le $DHCPLowPercentThreshold){

$messageParameters = @{

Subject = “Warning: DHCP Addresses Low”

Body = “$DHCPLowEventMessage”

From = $FromAddress

To = $ToAddress

SmtpServer = $SmtpServerAddress

}

Send-MailMessage @messageParameters

}

 

AD user DirectReports


Get-ADUser chadmin -Properties * | Select-Object -ExpandProperty DirectReports

Note : chadmin is user name

server up time report


$servers = "mccoyb02","foo","mccoyb01","reisrv1"
$path = "c:\ephemeral\uptime.html" 

$header = @"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>System Status Report</title>
<style type="text/css">
<!--
body {
background-color: #E0E0E0;
font-family: sans-serif
}
table, th, td {
background-color: white;
border-collapse:collapse;
border: 1px solid black;
padding: 5px
}
-->
</style>
"@
$body = @"
<h1>Server Status</h1>
<p>The following report was run on $(get-date).</p>
"@

$results = foreach ($server in $servers) 
{ 
    if (Test-Connection $server -Count 1 -ea 0 -Quiet) 
    { 
        $status = "Up" 
    } 
    else 
    { 
        $status = "Down"
    } 
    [PSCustomObject]@{
        ServerName = $server
        Reuslts = $status
    }
} 

$results | ConvertTo-Html -head $header -body $body | foreach {
    $PSItem -replace "<td>Down</td>", "<td style='background-color:#FF8080'>Down</td>"
} | Out-File C:\Ephemeral\uptime.html
& .\uptime.html


sample report:


Services status report


#========================================================================
# Check the services Information status
# Version 1.0 19-03-2019
# Created by: Test
#========================================================================
$date=Get-Date
$Header = @”
<style>

TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}

table
{
font-family:”Trebuchet MS”, Arial, Helvetica, sans-serif;
border-collapse:collapse;
}
td
{
font-size:1em;
border:1px solid #98bf21;
padding:5px 5px 5px 5px;
}
th
{
font-size:1.1em;
text-align:center;
padding-top:5px;
padding-bottom:5px;
padding-right:7px;
padding-left:7px;
background-color:#A7C942;
color:#ffffff;
}
name tr
{
color:#F00000;
background-color:#EAF2D3;
}

</style>
<h1>Services status</span></h1><br>

<h1>This report is generated on $date </span></h1><br>
“@

$GService = Get-WmiObject win32_service | select name,DisplayName,state,startname,startmode | ConvertTo-HTML -AS Table -Fragment | Out-String

# To change the services status color

$StatusColor = @{Stopped = ‘ bgcolor=”RED”>Stopped<‘;Running = ‘ bgcolor=”Green”>Running<‘;}
$StatusColor.Keys | foreach { $GService = $GService -replace “>$_<“,($StatusColor.$_) }

#Save the HTML Web Page
ConvertTo-HTML -head $Header -PostContent $GService|Out-File c:\temp\TableHTML.html

#Open TableHTML.html

Invoke-Item c:\temp\TableHTML.html

%d bloggers like this: