Verify if an update is installed


PS> $A = Get-Content -Path ./Servers.txt

PS> $A | ForEach-Object { if (!(Get-HotFix -Id KB957095 -ComputerName $_)) { Add-Content $_ -Path ./Missing-KB957095.txt }}

Note: 

The $A variable contains computer names that were obtained by Get-Content from a text file. The objects in $A are sent down the pipeline to ForEach-Object

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

}

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:


%d bloggers like this: