Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 180259

Issue with Powercli Get-Datastore when passing a string

$
0
0

So I am writing a powercli scrip that will take a cluster name and with a filter enumerate all the datastores on the cluster that are on our SAN. It will then snap the VMs so that I can issue a SAN snap. I am rather new to powershell so I realize this may not be the cleanest of scripts, but the main issue I am having is with this line:

 

$datastorelist = Get-Datastore -Name $arrayname -VMHost $nodelist

 

Any help would be greatly appreciated, thanks!

 

If I write the $nodelist to the screen it is formatted correctly and if copy the contents of $nodelist and hard code it into the parameter it works fine, but passing the string creates the following error:

 

Get-Datastore : 5/13/2013 8:26:29 AM    Get-Datastore        Could not find DatastoreRelatedObjectBase with name 'vh110

1119.mydomain.com,vhost20.mydomain.com,vhost18.mydomain.com,vhost02.mydomain.com,vhost03.mydomain.com,vhost04

.mydomain.com,vhost05.mydomain.com'.

At E:\Program Files\3par scripts\vmsnaps.ps1:64 char:32

+     $datastorelist = Get-Datastore <<<<  -Name $arrayname -VMHost $hostlist

    + CategoryInfo          : ObjectNotFound: (vhost19.mydom...05.mydomain.com:String) [Get-Datastore], VimException

    + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdle

   ts.Commands.GetDatastore

The scrip defines some variables and loads them, then calls  FindNode then QueryDatastores

 

Function FindNodes

#This function will take cluster and enumerate it to the hosts wthin it and add them to a comma delimited string

{

  Write-Host

  Write-Host Enumerating cluster nodes in $cluster cluster....

  #$nodes = Get-VMHost -Location $cluster

  $nodes = Get-Cluster $cluster | Get-VMHost

  Write-Host Found $nodes.Length nodes in cluster

  foreach ($i in $nodes) {

  $i.name

  $nodelist = $nodelist +","+$i.name

  $script:nodelist = $nodelist

  }

  $script:nodelist = $nodelist.substring(1)

}

 

 

Function QueryDatastores

# This function will enumerate the datastores on the given cluster that start with the $arrayname variable.

{

  Write-Host

  Write-Host Enumerating datastores on $cluster cluster, please wait.....

  Write-Host $nodelist

  $datastorelist = Get-Datastore -Name $arrayname -VMHost $nodelist

 

  Write-Host Found $datastorelist.Length datastores in $cluster cluster

  foreach ($i in $datastorelist) {

  $i.name

  }

 

}

 

 

Clear-Host

Write-Host

Write-Host Loading Powercli....

Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue

 

 

Write-Host Connecting to $vcenter "please wait...."

connect-viserver -server $vcenter

 

 

FindNodes

QueryDatastores


Viewing all articles
Browse latest Browse all 180259

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>