i am the funny
 

 I AM THE FUNNY!!!

So, any body who has worked with me will remember the annoyingly long HTA code that I wrote to send out outage notifications. Well, I am finally bringing it to the future with powershell!

This is the basic script to send an email, stay tuned for the GUI-ified version in the future!

<#
.SYNOPSIS
   Sends an email
.DESCRIPTION
   Email templates are used and modified after getting the required info
#>

##############################################
# Templates with the placeholders 
##############################################

# Instructions
$Instructions = @"
Hello,<br>
<br>
Can you please send this to: <br>
All Staff, local IT<br>
<br>
<br>
ALLEMAILS
<br><br>
Regards<br>
<br><br>
"@

# Header Table
$Header = @"
<div class=MsoNormal align=center style='text-align:center;line-height:115%'><span style='mso-bookmark:_MailAutoSig'><span style='font-size:10.0pt;line-height:115%;mso-ascii-font-family:Calibri;mso-fareast-font-family:Calibri;mso-hansi-font-family:Calibri;mso-bidi-font-family:Calibri;mso-no-proof:yes'><hr size=2 width="100%" align=center></span></span></div><br>
<br>
<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="100.0%" bgcolor="rgb(19,59,131)" style='width:100.0%;background:rgb(19,59,131)'>
    <tr>
        <td width=700 align=centre style='padding:0cm 0cm 0cm 0cm'><p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'>
            <img width="700" height="92.6" src="cid:itp_banner.jpg" alt="ITP Banner"/></span></font></p></td>
        <td border=0 style='padding:0cm 0cm 0cm 0cm'><p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p>&nbsp;</o:p></span></font></p></td>
    </tr>
</Table>
"@

#Severity Table
$Severity = @"
<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="100.0%"bgcolor="rgb(255,215,0)"style='width:100.0%;background:rgb(255,215,0)'>
    <tr bgcolor="rgb(255,215,0)">
        <td width=700 border=0 style='padding:0cm 0cm 0cm 0cm'>
            <p class=MsoNormal>
                <font size=3 face=Calibri>
                    <span style='font-size:11.0pt; font-family:Calibri'>
                        <o:p>
                            <img width="700" height=""18" src="cid:Minor_Out.png" alt="Minor Outage"/>
                        </o:p>
                    </span>
                </font>
            </p>
        </td>
        <td border=0 style='padding:0cm 0cm 0cm 0cm; text-align:right'>
            <p class=MsoNormal>
                <font size=2 face=Calibri>
                    <span style='font-size:10.0pt; font-family:Calibri'>
                        <o:p>&nbsp;
                    </span>
                </font>
            </p>
        </td>
    </tr>
</table>
"@

#Body fo the email
$PtoV = @"
<br>
<Font size="5" face="Calibri">
    What's happening?<br>
</font>
<Font size="3" face="Calibri">
    The 
</font>
<font color="red" size="3" face="Calibri">SERVERFROM</font>
<Font size="3" face="Calibri">
    site will be migrated to a new server of the same name. This change is scheduled at STARTTIME. Services will be available for start of business FINISHTIME.</font><br>
<br>
<Font size="4" face="Calibri">
    <u>PRINTERS:</u><br>
</font>
<br>
<Font size="3" face="Calibri">
    After the migration staff will need to update their printers. Your existing printers will be recreated onto 
</font>
<font color="red" size="3" face="Calibri">SERVERTO</font>
<Font size="3" face="Calibri">
    .<br>
    <br>
    To check what printers you currently have installed, click ‘Start’ button then select ‘Devices and Printers’ and make a note of the barcode number at the beginning of the queue name. 
    To install the new printer queue onto your PC, click ‘Start’ button then type in box 
</font>
    <font color="red" size="3" face="Calibri">‘\\SERVERTO'</font>
<Font size="3" face="Calibri">
    which will bring up a new window with all the print queues. <br>
    <br>
    Double click on the required printer to install. It will then leave an open window showing the print queue, which can be closed down. To remove the old queue from 
    ‘Devices and Printers’, right click on the required queue and select ‘Remove Device’ and click Yes to confirm.<br>
    <br>
    If you have the Ricoh Managed Print Solution, you can disregard this step, as your printers will automatically reconnect.<br>
    <br>
</font>
<Font size="4" face="Calibri">
    <u>NETWORK DRIVE MAPPING:</u><br>
</font>
<br>
<Font size="3" face="Calibri">
    Staff with manual drive mappings may need to manually map a drive to access their corporate data, otherwise group policy will automatically update to the new server path<br>
</font>
<br>
<Font size="4" face="Calibri">
    <u>FOR WINDOWS 7:</u><br>
</font>
<br>
<Font size="3" face="Calibri">
    <ol>
        <li>To connect a drive from My Computer, click <b>Start</b>, right-click <b>My Computer</b>, and then click <b>Explore</b>.</li>
        <li>On the Tools menu, click <b>Map Network Drive</b>.</li>
        <li>In the <b>Drive</b> box, click a drive letter <b>G:\</b>.</li>
        <li>In the <b>Folder</b> box, type the UNC path for the server and shared resource in the following format: <u>\\<b>SERVERTO</b>\GROUPDIR\</u></li>
        <li>Click Finish</li>
    </ol>
</font>
<Font size="4" face="Calibri"
    <u>FOR WINDOWS 10:</u><br>
</font>
<br>
<Font size="3" face="Calibri">
    <ol>
        <li>To connect a drive from My Computer, right-click Start and select <b>File Explorer</b>.</li>
        <li>Right-click on <b>This PC</b> on the left-hand pane and select <b>Map Network Drive</b>.</li>
        <li>In the <b>Drive</b> box, select drive letter <b>G:\</b>.</li>
        <li>In the <b>Folder</b> box, type the UNC path for the server and shared resource in the following format: <u>\\<b>SERVERTO</b>\GROUPDIR\</u></li>
        <li>Click Finish</li>
    </ol>
</font>
<Font size="4" face="Calibri">
    <u>SCANNING:</u><br>
</font>
<br>
<Font size="3" face="Calibri">
    Scanning will be delivered to and stored in the G:\SCANS\ directory. Files left in the SCANS directory will automatically be removed after 90 days.<br>
</font>
<br>
<Font size="5" face="Calibri">
    Impact to staff<br>
</font>
<Font size="3" face="Calibri">
    Staff will not be able to access File, Print and Network services. After the migration staff may need to update their printers. <br>
</font>
<br>
<Font size="5" face="Calibri">
    Affected services and sites<br>
</font>
<Font size="3" face="Calibri">
    Access to File, Print and Network Program Install services for all staff at the 
</font>
<font color="red" size="3" face="Calibri">SERVERFROM</font>
<Font size="3" face="Calibri">
    site.<br>
</font>
<br>
<Font size="5" face="Calibri">
    Time of outage<br>
</font>
<Font size="3" face="Calibri">
    STARTTIME to FINISHTIME
<br><br>
</font>
<Font size="5" face="Calibri">
    For further information<br>
</font>
<Font size="3" face="Calibri">
    Should you require further information please contact the Service Desk by <a href="mailto:servicedesk@contoso.com">email</a> or by telephone on 07 3000 0000<br>
    <br>
</font>
"@

# signature
$signature = @"
<Font size="2" face="Calibri">
    <br><br>
    Regards<br
    <br>
    Service Desk Team Leader<br>
    Information & Technology  For Life<br>
    <div class=MsoNormal align=center style='text-align:center;line-height:115%'><span style='mso-bookmark:_MailAutoSig'><span style='font-size:10.0pt;line-height:115%;mso-ascii-font-family:Calibri;mso-fareast-font-family:Calibri;mso-hansi-font-family:Calibri;mso-bidi-font-family:Calibri;mso-no-proof:yes'><hr size=2 width="100%" align=center></span></span></div>
    <b>Blah | Blah | Blah | and Partners</b><br>
    Floor 9 | 1 Brisbane Street | Brisbane Qld 4000<vr>
    GPO Box 888 | Brisbane Qld 4000<br>
    <br>
    Tel (07) 3000 0000 | Fax (07) 3000 0001<br>
</font>
"@

##############################################
# adding image attachment
##############################################

$path = "H:\scripts\PowerShell.SA\email\images"
$files= Get-ChildItem $path

##############################################
# Input all the info
##############################################

[string]$ServerFrom = Read-Host -Prompt 'Server moving from'
[string]$ServerTo = Read-Host -Prompt 'Server moving to'
[string]$StartTime = Read-Host -Prompt 'Starting (6.00pm FRIDAY 18 MAY 2018)'
[string]$FinishTime = Read-Host -Prompt 'From (7.00am MONDAY 21 MAY 2018.)'
[string]$email = Read-Host -Prompt 'Emails please'

##############################################
# Replace place holders with the new info
##############################################

$PtoV = $PtoV -replace "SERVERFROM", $ServerFrom
$PtoV = $PtoV -replace "SERVERTO", $ServerTo
$PtoV = $PtoV -replace "STARTTIME", $StartTime
$PtoV = $PtoV -replace "FINISHTIME", $FinishTime
$Instructions = $Instructions -replace "ALLEMAILS", $email

##############################################
# Buidling the email
##############################################

# create mail object
$ol = New-Object -comObject Outlook.Application 

# Create the emaisl
$mail = $ol.CreateItem(0)
$null = $Mail.Recipients.Add("ServiceDesk@contoso.com")  
$Mail.Subject = "Scheduled Maintenance - $ServerFrom - $StartTime to $FinishTime"
Foreach($File in $Files)
{
    Switch ($File.Name.ToString()) {
        "ITP_Banner.jpg" {
            Write-Host Attaching File :- $File"
            $mail.Attachments.Add($File.FullName)
        }
        "Minor_Out.png" {
            Write-Host Attaching File :- $File"
            $mail.Attachments.Add($File.FullName)
        }
    }
}    
$Mail.HTMLBody = $Instructions  + $Header + $Severity + $PtoV + $signature
$Mail.Display()