On line 29, where you define $vsmAsSource, you are performing a get-ncsnapmirror to determine if the volume is the source of a snapmirror relationship. The problem with that command is that if the snapmirror destination lives outside the cluster you are currently connected to, it will return with 0 results. This then causes an error later down the line of the command since the volume still potentially has a snapmirror relationship connected to it. In its place you should be running the 'get-ncsnapmirrordestination' commandlet to get the true results.
Thanks for informing the same.
Raised a bug for the same. BURT number is 959702.
We will investigate and update the BURT.