Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts

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.

Tuesday, June 19, 2012

How to Have a Daily PowerShell Report of your Exchange 2007 backups sent to you everyday.

Have you ever needed a way to quickly tell what was going on with your Exchange 2007 backups at night when you are not in the office? I came up with this script back in 2010 that helps you do that using PowerShell combined with Scheduled tasks on a Windows Server. Tested on Exchange 2007 and PowerShell v1 and v2.

We do Full Backups daily but if you want to, you can add “LastIncrementalBackup”or “LastDifferentialBackup” to suit your needs.

Here is the script:
------------------------------------------------------------------------------------------------------------
#######################################
#Backup_report_vs1.ps1                #
#http://imjustanengineer.blogspot.com #
#Created by DJ 6/2/2010               #
#######################################

Add-PSSnapin Microsoft.Exchange.Management.powershell.admin;

Get-Mailboxserver | Get-MailboxDatabase -Status |FL Name,Server,lastfullbackup,backupinprogress,Mounted > c:\exch2007_backups.txt

start-sleep -s 120

$filename = “c:\exch2007_backups.txt”
$smtpServer = “your.smtpserver.com” #Enter FQDN of your SMTP server

$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = “BackupReportingScript@yourdomain.com” #Enter senders email address $msg.To.Add(”recipient1@yourdomain.com, recipient2@yourdomain.com,”) #Enter one or more recipient addresses
$msg.Subject = “Exchange 2007 Servers Backup Report" #Enter subject of message $msg.Body = “Attached is the Daily Exchange 2007 Servers Backup Report. Please note any servers that have not been backed up for more than a day.” $msg.Attachments.Add($att)

$smtp.Send($msg)
-----------------------------------------------------------------------------------------------------------

In the created text file on your C: drive you should output that looks like

Name             : EXCH-SERVER01_SG01DB01
Server           : EXCH-SERVER01
LastFullBackup   : 6/7/2010 2:33:10 AM
BackupInProgress : False
Mounted          : True



Please let us know if this is helpful to you.