any idea why I am getting this error?
$VMs = get-content vms.txt
foreach ($VM in $VMs)
{
$VMDK = $VM | get-harddisk }
sk
Get-HardDisk : Cannot process argument transformation on parameter 'Datastore'. Strings as pipeline input are not supported.
At line:1 char:7
+ $VM | Get-HardDisk
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (xjzxbwg1105x:PSObject) [Get-HardDisk], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.GetHardDisk
I suppose the content of the file vms.txt has a list of VM Names.
So when you import it in the variable $VMs, it has a list of the VM Names. Similarly $VM has a string value with the name of a VM. So in the "$VMDK = $VM | get-harddisk" you are essentially giving a string value and trying to get the Get-Harddisk of the VM. This is obviously failing as the pipeline input should an object.
Change it to "Get-VM $VM | Get-HardDisk" Should do.
$VMs = get-content vms.txt
foreach ($VM in $VMs)
{
$VMDK = Get-VM $VM | get-harddisk }
I suppose the content of the file vms.txt has a list of VM Names.
So when you import it in the variable $VMs, it has a list of the VM Names. Similarly $VM has a string value with the name of a VM. So in the "$VMDK = $VM | get-harddisk" you are essentially giving a string value and trying to get the Get-Harddisk of the VM. This is obviously failing as the pipeline input should an object.
Change it to "Get-VM $VM | Get-HardDisk" Should do.
$VMs = get-content vms.txt
foreach ($VM in $VMs)
{
$VMDK = Get-VM $VM | get-harddisk }
thank you