PowerCLI

 View Only
  • 1.  cmdlet ForEach-Object at command pipeline position 2

    Posted Feb 28, 2011 03:40 PM

    Hi all,

    I have the following script I wrote and for some reason when I run it, I get a "supply values for the following parameter" although all the parameters values were included in a CSV file I created for input.

    The script is used for mapping virtual disks to my VMs.

    This is my script:

    Import-Csv -Path Luns.csv | ForEach-Object `
    {
      $vm = Get-VM $_.VM
      $LunType = $_.LunType
      if (LunType eq "RDMP")
      {
        $Lun = $_.Lun
        $deviceName = ($vm | Get-VMHost | Get-ScsiLun | Where-Object {$_.RunTimeName.Split(":")[3].TrimStart("L") -eq $Lun}).ConsoleDeviceName 
        New-HardDisk -VM $vm -DiskType RawPhysical -DeviceName $deviceName
      }
      elseif (LunType eq "VMFS")
      {
        $LunSize = $_.LunSize
        $Datastore = $_.DataStore
        New-HardDisk -VM $vm -Datastore $Datastore -CapacityKB $LunSize*1024*1024
      }
      Invoke-VMScript -vm $vm -guestuser administrator -guestpassword kashya -scripttype bat -scripttext "diskpart /s c:\part.txt"
      Invoke-VMScript -vm $vm -guestuser administrator -guestpassword kashya -scripttype bat -scripttext "echo y | format e: /q /fs:ntfs /v:"
    }

    And this is my CSV:

    VMLunLunTypeLunSizeDataStore
    Clus1VM31RDMP
    Clus1VM32RDMP
    Clus1VM53RDMP
    Clus1VM5VMFS5DS3
    Clus1VM65RDMP
    Clus1VM7VMFS5DS3

    Thanks for the help,

    Nir



  • 2.  RE: cmdlet ForEach-Object at command pipeline position 2

    Posted Feb 28, 2011 05:23 PM

    Perhaps something went wrong with the copy paste, but the comparison statements should say

    if($_.LunType -eq "RDMP")

    and

    elseif ($_.LunType -eq "VMFS")

    or (if you want to use the local variable)

    if($LunType -eq "RDMP")
    ...
    elseif ($LunType -eq "VMFS")