VMware Cloud Community
stuarty18742011
Contributor
Contributor
Jump to solution

Strings as pipeline input are not supported.

Guys,  I have this script to add a vDisk to each VM via a Foreach Loop ...

$VMNames = Get-Content 'E:\Code\Scripts\VMware-VM-UpgradevHardware\VM_Batch-1.txt'

# BEGIN foreach loop

foreach ($vm in $VMnames) {

#Perform paraSCSI Update

Write-Host $VM

Write-Host 'Adding New Tempoary virtual disk...'

# Get-Vm $vm | New-Harddisk -CapacityKB 2048 -Persistence persistent

$vm | New-HardDisk -CapacityKB 2048 -Persistence persistent

Read-Host "Lets pause and verify ... ..."

. .but when I run it I get this error.

New-HardDisk : Cannot process argument transformation on parameter 'VM'. Strings as pipeline input are not supported.

At E:\code\Scripts\VMware-VM-UpgradevHardware\pvSCSIUpdate3.ps1:55 char:7

+ $vm | New-HardDisk -CapacityKB 2048 -Persistence persistent

+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (EDM-SNEC-DBTEST:PSObject) [New-HardDisk], ParameterBindingArgumentTransformationException

    + FullyQualifiedErrorId : ParameterArgumentTransformationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk

Lets pause and verify ... ...:

Any suggestions??

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You should have a VirtualMachine object (output from Get-VM) on the pipeline, if you want to send it to the New-HardDisk cmdlet.

The Object By Name (OBN) concept doesn't work for pipeline input here.

You can do

# BEGIN foreach loop

foreach ($vm in (Get-VM -Name (Get-Content 'E:\Code\Scripts\VMware-VM-UpgradevHardware\VM_Batch-1.txt'))){

    #Perform paraSCSI Update

    Write-Host $VM.Name

    Write-Host 'Adding New Tempoary virtual disk...'

    New-HardDisk -VM $vm -CapacityKB 2048 -Persistence persistent

    Read-Host "Lets pause and verify ... ..."

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

You should have a VirtualMachine object (output from Get-VM) on the pipeline, if you want to send it to the New-HardDisk cmdlet.

The Object By Name (OBN) concept doesn't work for pipeline input here.

You can do

# BEGIN foreach loop

foreach ($vm in (Get-VM -Name (Get-Content 'E:\Code\Scripts\VMware-VM-UpgradevHardware\VM_Batch-1.txt'))){

    #Perform paraSCSI Update

    Write-Host $VM.Name

    Write-Host 'Adding New Tempoary virtual disk...'

    New-HardDisk -VM $vm -CapacityKB 2048 -Persistence persistent

    Read-Host "Lets pause and verify ... ..."

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos