Hey William,
I took a stab at making it work this morning and I was able to get a basic form of it going. It’s not doing every data point, I just did 1 data point as a test.
Here is what I did:
First, I edited the Step Template and modified the following code:
Set-OctopusVariable -name "NumDrives" -value "$($drivelist.Count)"
# ================= RUN CHECKS =================
$i = 0
foreach($d in $driveList) {
$driveDescr = "$($d.DeviceID) [$($d.VolumeName)]"
$pDrivespaceGBFree = [Math]::Round(($d.FreeSpace / [Math]::Pow(1024,3)), 1)
$pDrivespaceGBTotal = [Math]::Round(($d.Size / [Math]::Pow(1024,3)), 1)
$pDrivespacePercentFree = [Math]::Round($pDrivespaceGBFree / $pDrivespaceGBTotal,1) * 100
Write-Host "Drive $driveDescr : Free $pDrivespaceGBFree GB ($pDrivespacePercentFree%), Total $pDrivespaceGBTotal GB"
Set-OctopusVariable -name "Drive$($i)" -value "Drive $driveDescr : Free $pDrivespaceGBFree GB ($pDrivespacePercentFree%), Total $pDrivespaceGBTotal GB"
if ($checkSpaceAbsolute) {
if ($pDrivespaceGBFree -lt $pSpaceGB) {
Write-Error "Drive $driveDescr has less than the required space ($pSpaceGB GB)"
}
}
if ($checkSpacePercent) {
if ($pDrivespacePercentFree -lt $pSpacePercent) {
Write-Error "Drive $driveDescr has less than the required space ($pSpacePercent %)"
}
}
$i++
}
-
First I created an output variable for numdrives and did a count on the drivelist array to see how many drives there were. We use this in the next step of the process
-
Then I created $i to create a dynamic amount of output variables. $i =0 before the loop starts, and $i++ at the end of the loop.
-
The big add here is this line:
Set-OctopusVariable -name "Drive$($i)" -value "Drive $driveDescr : Free $pDrivespaceGBFree GB ($pDrivespacePercentFree%), Total $pDrivespaceGBTotal GB"
This will create the dynamic output variable to later be iterated through.
Our next step is to collate the data into one output variable to mail. I did a run a script(on the server or worker) with the following logic:
$machines = @()
#{each machine in Octopus.Action[Run A Script].Output}
$machines += "#{machine}"
#{/each}
$dataforemail
$machines = $machines | Sort-Object
$machines | ForEach-Object {
Write-Highlight $_
$drivecount = $OctopusParameters["Octopus.Action[Run A Script].Output[$_].NumDrives"]
for ($i=0;$i -lt $drivecount;$i++){
$drivedata = $OctopusParameters["Octopus.Action[Run A Script].Output[$_].Drive$($i)"]
Write-Highlight $drivedata
$dataforemail += $_
$dataforemail += "<br>"
$dataforemail += $drivedata
$dataforemail += "<br>"
}
}
Set-OctopusVariable -name "EmailData" -value "$dataforemail"
- This first creates an array of all the machines to later iterate through.
- Then we create a variable that we will add all of the data to ($dataforemail)
- Then we go through machine, set the number of drives for the for loop, iterate through the drives and add the data to $dataforemail.
- Once all the data has been added, we simply put this in an output variable.
Finally, we have the email step:
All of this results in the following email:

There is a double title for the name of the tentacle for extra drives, but you could put an if statement for if $i -eq 0 so that you only get one machine name to resolve that.
For instance:
if ($i -eq 0){
$dataforemail += $_
}
$dataforemail += "<br>"
$dataforemail += $drivedata
$dataforemail += "<br>"
I hope I explained that properly.
Please let me know if you get it going on your end or if you have any questions.
Thanks,
Jeremy