Showing posts with label Windows PowerShell. Show all posts
Showing posts with label Windows PowerShell. Show all posts

Tuesday, February 10, 2015

How to count the number of DC's in your forest and individual domains with PowerShell

For some reason, with all the power of the internets, this answer was nowhere to be easily found.

I needed to be able to count the number of (Domain Controllers) DC's in our forest, and also for a specific domain. It's a simple PowerShell script ... here is what I used



cls

$domains = (Get-ADForest).Domains;

foreach ($domain in $domains)

{

    Write-Host $domain
    (Get-ADDomain -Identity $domain | select -ExpandProperty ReplicaDirectoryServers).Count;
    Write-Host "";
    $totalCount = $totalCount + (Get-ADDomain -Identity $domain | select -ExpandProperty ReplicaDirectoryServers).Count;
}

Write-Host "Total domain controller count is: "$totalCount

Thursday, March 6, 2014

Fun With PowerShell (Make it Speak)

In my downtime, I wanted to have some fun with PowerShell and make it speak using Add-Type -AssemblyName System.Speech. I have always written an age calculation script in every scripting language I have learned and I realized I had never done one in PowerShell. So I wrote one and decided to have it speak to you. Here it is:

---------------------------------------------------------------------------------
######################################## 
# Funscript.ps1                        # 
# http://imjustanengineer.blogspot.com #
# Written by DJ 3/2014                 #
######################################## 

Add-Type -AssemblyName System.Speech
$synthesizer = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer

Write-Host This script will tell you how old you will be in $year and will speak to you. Make sure your speakers are on.;
$synthesizer.Speak("This script will tell how old you will be in ($year) and will speak to you. Make sure your speakers are on. ") | Out-Null
$name = Read-Host 'What is your name?';
$synthesizer.Speak("Hello, ($name) ,!") | Out-Null
$yb = Read-Host 'What year were you born?';
$synthesizer.Speak("Thank you, ($name) ,") | Out-Null
$date = Get-Date;
$year = + $date.Year;
$today = Get-Date -Format D;
$span = $year - $yb;
Write-Host Hello, $name. Today is $today. You will be $span years old this year. When is the party?;
$synthesizer.Speak("Hello, ($name). Today is ($today). You will be ($span) years old this year. When is the partee? ") | Out-Null
[System.Console]::Beep(262,200)
[System.Console]::Beep(262,200)
[System.Console]::Beep(294,200)
[System.Console]::Beep(262,200)
[System.Console]::Beep(349,200)

[System.Console]::Beep(330,200)
[System.Console]::Beep(262,200)
[System.Console]::Beep(262,200)
[System.Console]::Beep(294,200)
[System.Console]::Beep(262,200)
[System.Console]::Beep(392,200)
[System.Console]::Beep(349,200)
[System.Console]::Beep(262,200)
[System.Console]::Beep(262,200)
[System.Console]::Beep(482,200)
[System.Console]::Beep(440,200)
[System.Console]::Beep(349,200)
[System.Console]::Beep(330,200)
[System.Console]::Beep(294,200)
[System.Console]::Beep(482,200)
[System.Console]::Beep(482,200)
[System.Console]::Beep(440,200)
[System.Console]::Beep(349,200)
[System.Console]::Beep(392,200)
[System.Console]::Beep(349,200)




I would like to see what you can come up with. Be sure to leave your comments and suggestions below.