Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 49146

Re: Function from THE book : vSphere PowerCLI Reference

$
0
0

So, I tried to import inventory in a new fresh vCenter 6.0 but it still does not work. I'm pretty confident that the function Get-VILocation does not what it should,

let me explain. Recreate the root Folder structure works well :

 

$folderstructure['Datacenters'] | New-FolderStructure -Parent Datacenters

 

This is OK, Folders has been created successfully. But, when it comes to recreating Datacenters objects, Get-VILocation returns an error.

 

In my environment, I got two DC objects. One of the root of the vCenter (just like your DC1 and Homelab in your screenshot). Let's call it DC1 as well. And another in a folder : Folder01, called DC2 Like I said, the folder Folder01 has been created successfully

 

The VIPath property of my DC are : DC1 Folder01\DC2 And here,

 

the error when I try to recreate DC (New-Datacenter) : 

Get-Folder Folder with name 'DC01' was not found using the specified filter(s)

Get-Folder Folder with name 'DC02' was not found using the specified filter(s)

 

I tried to track what's actually happening in the function Get-VILocation :

 

foreach ($dc in Import-Clixml -Path "C:\Migration\Datacenters.xml") {

     New-Datacenter -Location ($dc.VIPath | Get-VILocation -parent Datacenters) -Name $dc.Name

}

 

We are sending to Get-VILocation : $dc.VIPath Like I wrote earlier, $dc.VIPath  are "DC1" and "Folder01\DC2" and the $parent sent to the function is always 'Datacenters'

 

I tried to 'monitor' the function with some Write-Host  $_ = DC1 or Folder01\DC2

 

The core of the function is : $folder = Get-Folder -Name$_ -Location $folder

 

I will remplace variables :

 

for $dc.vipath =  DC1 :

Get-Folder -Name DC1 -Location Datacenters =>  NOK, Folder, does not exists

 

For $dc.vipath = Folder01\DC2  (due to the .Split('/'), there will be two iterations

Get-Folder -Name Folder01 -Location Datacenters  => OK, folder exists

Get-Folder -Name DC2 -Location Datacenters  => NOK, Folder, does not exists

 

Finaly, the cmdlet New-Datacenter fails because he could not validate the mandatory parameter -Location

I may be totally wrong, but I don get why we are trying to get a folder named like a Datacenter Object.

 

Regards, Nicolas


Viewing all articles
Browse latest Browse all 49146

Trending Articles



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