Automation

 View Only
  • 1.  get-folder

    Posted Mar 30, 2011 09:24 PM

    Hello community,

    get-folder does not include the network folders under Home > Inventory > Networking. correct?

    Is there an other command for these folders?

    regards, Sven



  • 2.  RE: get-folder

    Posted Mar 30, 2011 09:35 PM

    I try to move around 400 Networks from a folder called "Old" (under Enterprise (Home > Infrastructure > Networking)) to dedicated folder Exampe1 and Example2 under Enterprise. It su.... by hand ;-)

    regards, Sven



  • 3.  RE: get-folder

    Posted Mar 30, 2011 09:53 PM

    The current Get-Folder cmdlet doesn't support the Network folders.

    There is a network folder under each datacenter.

    You can get the folder like this

    $dc = Get-Datacenter MyDC
    $net = Get-View $dc.ExtensionData.NetworkFolder
    $netImpl = Get-VIObjectByVIView $net.MoRef
    $netImpl

    The $netImpl variable will hold the folder object.

    You can now do things like

    New-Folder -Name Test -Location $netImpl


  • 4.  RE: get-folder

    Posted Mar 31, 2011 02:43 PM

    Hi Luc

    Many thanks!

    May you have a solution to move the networks into this Network folder?

    Because I would like set the permission on this level and not on enterprise.

    regards, Sven



  • 5.  RE: get-folder

    Posted Mar 31, 2011 07:38 PM

    That's possible but you will have to fall back on the SDK method.

    The following creates a new folder Test under the network folder and then moves the portgroup, called testPG, to that folder.

    $datacenterName = "MyDC"
    $newFolder = "Test"
    $pgName = "TestPG"
    $dc = Get-Datacenter -Name $datacenterName
    $networkFolder
    = Get-View $dc.ExtensionData.NetworkFolder $networkFolderImpl = Get-VIObjectByVIView $net.MoRef # Create subfolder
    $dest = New-Folder -Name $newFolder -Location $netImpl
    # Find portgroup
    $pg = $networkFolder.ChildEntity | %{Get-View $_} | where {$_.Name -eq $tgtPG} # Move portgroup to folder
    $dest
    .Extensiondata.MoveIntoFolder($pg.MoRef)


  • 6.  RE: get-folder

    Posted Apr 06, 2011 04:34 PM

    I have to move arround 200 portgroups. Can I set

    $pgName = "TestPG,TestPG1,TestPG2"

    regards, Sven


  • 7.  RE: get-folder

    Posted Apr 06, 2011 04:59 PM

    You can, but you will have to change the condition on the Where clause.

    Something like this

    $datacenterName = "MyDC" 
    $newFolder = "Test" 
    $tgtName = "TestPG,TestPG1,TestPG2"
    
    $dc
    = Get-Datacenter -Name $datacenterName $networkFolder = Get-View $dc.ExtensionData.NetworkFolder $networkFolderImpl = Get-VIObjectByVIView $networkFolder.MoRef # Create subfolder 
    $dest = New-Folder -Name $newFolder -Location $networkFolderImpl
    #
    Find portgroup
    $pg = $networkFolder.ChildEntity | %{Get-View $_} | where {$tgtName -contains $_.Name} # Move portgroup to folder
    $dest.Extensiondata.MoveIntoFolder($pg.MoRef)


  • 8.  RE: get-folder

    Posted Apr 06, 2011 06:57 PM

    I get an error

    Get-VIObjectByVIView : Cannot validate argument on parameter 'VIView'. The argu
    ment is null or empty. Supply an argument that is not null or empty and then tr
    y the command again.

    regards, Sven



  • 9.  RE: get-folder

    Posted Apr 06, 2011 07:03 PM

    There was a typo, it's corrected.