The script tests for the type of the parameter in
if($_ -is [VMware.VimAutomation.Types.VirtualMachine])
In the newer builds of PowerCLI that is not the correct name of the VirtualMachine type.
It should be
VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl
Try changing the line where the test is done into
if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl])
Which PowerCLI version are you running ? Do a
Get-PowerCLIVersion