# Help with a legacy script

**URL:** <https://forums.powershell.org/t/help-with-a-legacy-script/19158>\
**Category:** PowerShell Help\
**Created:** [April 22, 2022, 8:04am UTC](https://forums.powershell.org/t/help-with-a-legacy-script/19158 "2022-04-22T08:04:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![F022Y](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@F022Y](https://forums.powershell.org/u/F022Y)\
**Post date:** [April 22, 2022, 8:04am UTC](https://forums.powershell.org/t/help-with-a-legacy-script/19158/1 "2022-04-22T08:04:24Z")

</div>

Hello all,

Some years ago the company hired a contractor to write a PS script to check for servers that were awaiting reboot via WSUS GPOs and give them a kick, after which it then logged this and sent an email.

Here I am today trying to understand how it works because we have a new GPO which we want to cover but since adding it the script runs but we don’t get the export or email, i’m not sure how best to proceed as the script does contain info like mailservers and the like.

Any help appreciated.

Foz

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 22, 2022, 8:24am UTC](https://forums.powershell.org/t/help-with-a-legacy-script/19158/2 "2022-04-22T08:24:21Z")

</div>

F022Y,  
Welcome to the forum. 👋🏽

This is a peer to peer forum where we help each other with self written code. We do not review or refactor complete scripts or solutions, sorry.

I’d recommend to start to learn the fundamentals of PowerShell first. This will save you from a lot of wasted time and frustrations.

In general: when you have sensitive information embedded in the code you need to post you should obfuscate those information.

---

<div class="post-metadata">

**Author:** ![F022Y](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@F022Y](https://forums.powershell.org/u/F022Y)\
**Post date:** [April 22, 2022, 8:35am UTC](https://forums.powershell.org/t/help-with-a-legacy-script/19158/3 "2022-04-22T08:35:14Z")

</div>

Hello Olaf,

Sorry should have said that i’m familiar with PS but clearly the guy who wrote this has done some things i’m not familiar with as i have amended it previously with no issue but not this section.

I only ask about sensitive info as previously i’ve known sites ask for the whole script and this beast is 242 lines.

The section i’m interested is as follows:-

# Prepare the email to send to Infrastructure team with links to logs

```
$SMTPSvr = $SMTPServer
$From = $SendFrom
$To = $SendTo
$Subject = ("WSUS 2016 Auto Update Reboot Status - " + $todaysDate)

$Body = ("<html><head></head><body bgcolor=White><p>"+$FontSmall+"Can't read this? <a href='http://webadcu/WSUS/$HTMLFileName'>View in browser</a></font></p><p align=Left><img src='Corporate image' width='79' height='37'></p><p>"+$FontNormal+"Please find below the report for WSUS Auto-Rebooting the following servers:</font></p><p>"+$FontNormal+"Total Computers in GPO's:<br>" + $GPO + ": <font color=#000c52><b>" + $TotalGPO + "</b></font><br>" + $GPO2 + ": <font color=#000c52><b>" + $TotalGPO2 + "</b></font><br>" + $GPO3 + ": <font color=#000c52><b>" + $TotalGPO3 + "</b></font><br>" + $GPO4 + ": <font color=#000c52><b>" + $TotalGPO4 + "</b></font><br>" + $GPO5 + ": <font color=#000c52><b>" + $TotalGPO5 + "</b></font><br>" + $GPO6 + ": <font color=#000c52><b>" + $TotalGPO6 + "</b></font><br><br>" "Total Computers in all Auto Update GPO's: <font color=#000c52><b>" + $TotalComputers + "</b></font><br>Total Computers Rebooted: <b>" + $TotalReboots + "</b><br>Total Computers Not Rebooted: <b>" + $TotalNoReboots + "</b><br>Total Computers WMI Errors: <b>" + $TotalWMIErrors + "</b><br>Total Computers Non-contactable: <b>" + $TotalNonContact + "</b></font></p>")
    $Body += "<table width='100%' cellspacing=0 cellpadding=0 border=0 height=20><tr><td width='200' height='1'><img src='Corporate image' width='200' height='1' border=0></td><td width='200' height='1'><img src='Corporate image' width='200' height='1' border=0></td><td width='200' height='1'><img src='Corporate image' width='200' height='1' border=0></td><td width='100%' height='1'><img src='Corporate image' width='100%' height='1' border=0></td></tr>"
    $Body += "<tr><td width='100%' height='20' colspan='4'>"+$FontHeading+"<b>Computers Rebooted</b></font></td></tr><tr><td width='200' height='20'>"+$FontNormal+"<b>Computer Name</b></font></td><td width='200' height='20'>"+$FontNormal+"<b>Status</b></font></td><td width='200' height='20'>"+$FontNormal+"<b>Time Rebooted</b></font></td><td width='100%' height='20'><img src='Corporate image' width='100%' height='20' border=0></td></tr>"
    $Body += "<tr bgcolor='#CCCCCC'><td width='200' height='1'><img src='Corporate image' width='200' height='1' border=0></td><td width='200' height='1'><img src='Corporate image' width='200' height='1' border=0></td><td width='200' height='1'><img src='Corporate image' width='200' height='1' border=0></td><td width='100%' height='1'><img src='Corporate image' width='100%' height='1' border=0></td></tr>"
    $Body += $RebootArray
    $Body += "<tr><td width='200' height='20'><img src='Corporate image' width='200' height='20' border=0></td><td width='200' height='20'><img src='Corporate image' width='200' height='20' border=0></td><td width='100%' height='20' colspan='2'><img src='Corporate image' width='100%' height='20' border=0></td></tr>"
    $Body += "<tr><td width='100%' height='20' colspan='4'>"+$FontHeading+"<b>Computers Not Rebooted</b></font></td></tr><tr><td width='200' height='20'>"+$FontNormal+"<b>Computer Name</b></td><td width='200' height='20'>"+$FontNormal+"<b>Status</b></td><td width='100%' height='20' colspan='2'><img src='Corporate image' width='100%' height='20' border=0></td></tr>"
    $Body += "<tr bgcolor='#CCCCCC'><td width='200' height='1'><img src='Corporate image' width='200' height='1' border=0></td><td width='200' height='1'><img src='Corporate image' width='200' height='1' border=0></td><td width='100%' height='1' colspan='2'><img src='Corporate image' width='100%' height='1' border=0></td></tr>"
    $Body += $NoRebootArray
    $Body += "</table><p><font style='font-family: Calibri,Tahoma,Verdana; font-size: 12; color: #333333'>Please check the full log at <a href='file://Script Server/WSUS/$FileName'>\\Script Server\WSUS\$FileName</a>.<br><br>This is an automated email. Do not reply to this email.</font></p></body></html>"

#### Now send the email using Send-MailMessage  
Send-MailMessage –From $From –To $To –Subject $Subject –Body $Body -BodyAsHtml -SmtpServer $SMTPSvr -Port 25

# Create the html file to view in browser
$Body | Out-File ($ExportFilePath + $HTMLFileName) -Encoding ascii

```

---

<div class="post-metadata">

**Author:** ![F022Y](https://avatars.discourse-cdn.com/v4/letter/f/45deac/32.png) [@F022Y](https://forums.powershell.org/u/F022Y)\
**Post date:** [April 22, 2022, 8:40am UTC](https://forums.powershell.org/t/help-with-a-legacy-script/19158/4 "2022-04-22T08:40:21Z")

</div>

The only bit i’ve added is the $GPO6 and $TotalGPO6 across the script

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 22, 2022, 9:20am UTC](https://forums.powershell.org/t/help-with-a-legacy-script/19158/5 "2022-04-22T09:20:57Z")

</div>

Hmmm … I assume you do not use VSCode, do you? 😉

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/f/f1bb7fbb639bd4ffd8c7b3d80e6424f91ff23391.png)  
Either you remove the consecutive double quotes or you add a plus between them.

Regardless of that - I urgently recommend for you to read about here strings. It could make your code way easier to read.

> **[Informationen zum Anfügen von Regeln - PowerShell](https://docs.microsoft.com/de-de/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.2#here-strings)**
>
> Beschreibt Regeln für die Verwendung einzelner und doppelter Anführungszeichen in PowerShell.

Next you may read about creating HTML reports with PowerShell.

> **[How To Create An HTML Report With PowerShell](https://adamtheautomator.com/html-report/)**
>
> Learn how to use the PowerShell ConvertTo-HTML cmdlet and CSS to create a beautiful HTML report with PowerShell that makes the report easier to understand.

That could make the HTML part way easier to write and to maintain if needed.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:18pm UTC](https://forums.powershell.org/t/help-with-a-legacy-script/19158/6 "2024-05-16T20:18:02Z")

</div>


