I created a PowerShell script to search the datastore for VMs with snapshots. These VMs are not registered in vCenter, so I can't use the Get-Snapshot command. However, the script works by reading the disk path, opening the VMX file, and identifying which snapshot is in use. I then pass this path to the New-HardDisk command to attach the snapshot to one of my live VMs.
The problem arises when I execute the New-HardDisk command, my ESXi host immediately disconnects from vCenter, and all datastores and VMs are marked as disconnected or inaccessible. Interestingly, if I manually attach the same VMDK from the vCenter console, there are no disconnection or inaccessibility issues.
The command for attaching the VMDK file is:
New-HardDisk -DiskPath "[NFS_2] WIN-NFS2-01/WIN-NFS2-01-000001.vmdk" -VM $myVM
From the vCenter console, I can open the datastore, navigate to the folder WIN-NFS2-01, select the file WIN-NFS2-01-000001.vmdk, and everything works fine.
Does anyone know what might be causing the disconnection or inaccessibility issue when I use the PowerShell command?