It looks as if you are not using PowerShell v3.
In that version the problem with a foreach loop over an empty array has been fixed.
When there are no entries in the array, the code block will not be executed.
In PowerShell v2 you will have to check yourself in the script if Get-HardDisk returns anything.
I don't see how my solution will execute the first codeblock for a non-existing 2nd harddisk.
Perhaps you can attach the code you are using ?