VMware Cloud Community
xooops
Contributor
Contributor

get-folder

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

Reply
0 Kudos
8 Replies
xooops
Contributor
Contributor

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

Reply
0 Kudos
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

xooops
Contributor
Contributor

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

Reply
0 Kudos
LucD
Leadership
Leadership

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)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
xooops
Contributor
Contributor

I have to move arround 200 portgroups. Can I set

$pgName = "TestPG,TestPG1,TestPG2"

regards, Sven
Reply
0 Kudos
LucD
Leadership
Leadership

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)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
xooops
Contributor
Contributor

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

Reply
0 Kudos
LucD
Leadership
Leadership

There was a typo, it's corrected.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos