Automation

 View Only
  • 1.  Foreach statement fails for new-datastore

    Posted Nov 19, 2015 04:26 PM

    Hi there,

    Currently trying to attach NFS datastores to a freshly installed ESXi host using the following foreach statement below:

    foreach ($Datastore in (Get-vmhost source-esx.domain.com | Get-Datastore | where {$_.Type -eq "nfs" -and $_.Accessible -eq "true"})) {New-Datastore -Nfs -VMHost dest-esx.domain.com -Name $Datastore.Name -Path $Datastore.RemotePath -NfsHost $Datastore.RemoteHost}

    The command failes with "Value cannot be found for the mandatory parameter VMHost" within the "New-Datastore" portion of the command.  Running PowerCLI 5.5 R1 Build 1295336.

    Any suggestions on how to get around this error would be much appreciated!

    ~Pete



  • 2.  RE: Foreach statement fails for new-datastore

    Posted Nov 19, 2015 06:42 PM

    I'm unsure of why the original wouldn't work however breaking it down to the following allowed me to successfully run the script:

    $Datastore = (Get-vmhost source-esx.domain.com | Get-Datastore | where {$_.Type -eq "nfs" -and $_.Accessible -eq "true"})

    foreach ($objItem in $Datastore){New-Datastore -Nfs -VMHost dest-esx.domain.com-Name $objItem.Name -Path $objItem.RemotePath -NfsHost $objItem.RemoteHost}

    ~Pete



  • 3.  RE: Foreach statement fails for new-datastore

    Posted Nov 19, 2015 06:42 PM

    Does this actually return a VMHost object ?

    Get-VMHost -Name dest-esx.domain.com



  • 4.  RE: Foreach statement fails for new-datastore

    Posted Nov 19, 2015 06:45 PM

    Hi LucD,

    Yes, running just that snippet returns the VMhost information.  I just posted above this with my work-around that did the trick for me.

    Thanks!

    ~Pete