VMware Cloud Community
VirtualNoitall
Virtuoso
Virtuoso
Jump to solution

Get-Folder myfolder | Get-VM displays nothing

Hello,

This is likely just a little oversite but I issue the above command with the folder name I am querying, in place of myfolder, and get nothing returned. If I just issue the "Get-Folder myfolder" command I see the folder and the id listed. If I just issue the Get-VM command I of course get all theVMs in my Virtual Center. When I try to put both together though, as shown in the VMware Powershell reference index page, I get nothing. Does anyone have any ideas?

Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

I looked at this a bit more closely using the managed object browser and found that my vms are in fact directly attached to the vm folder and not directly attached to ha-folder-root. I agree that this is a bug and needs to be fixed in an upcoming release, and have filed a bug with development.

Carter

View solution in original post

Reply
0 Kudos
15 Replies
halr9000
Commander
Commander
Jump to solution

I get the same behavior. A bug perhaps.

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
VirtualNoitall
Virtuoso
Virtuoso
Jump to solution

wow, this is pretty basic. I know this isn't yet ready for release but this is pretty fundamental stuff. Smiley Sad

We do a lot of reporting so this pretty much kills powershell for us for a bit

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

I'd cut them a little slack. I've reported several bugs but everything that works is very stable. For the time being, there are several other ways to filter things that might help for you. But a little more fiddling does seem to confirm that get-folder does not return the right type of object for get-vm's -location parameter.

76# Get-VM -Location

Get-VM : Missing an argument for parameter 'Location'. Specify a parameter of type 'VMware.VimAutomation.Types.VIContainer[]' and try again.

75# Get-Folder | gm

TypeName: VMware.VimAutomation.Client20.FolderImpl

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
admin
Immortal
Immortal
Jump to solution

Hi,

It works in my experience, what can be a bit tricky is knowing which folder to use, since they don't necessarily map to the stuff you see in VI Client.

Here's a capture of a session I ran:

PS C:\Documents and Settings\cshanklin> get-folder

Name Id -


-- vm Folder-ha-folder-vm host Folder-ha-folder-host ha-folder-root Folder-ha-folder-root

PS C:\Documents and Settings\cshanklin> get-folder vm | get-vm PS C:\Documents and Settings\cshanklin> get-folder ha-folder-root | get-vm

Name PowerState Num CPUs Memory (MB) -


-
-
-
fromsan1 PoweredOn 1 256 fromsan1 (1) PoweredOff 1 256 onsan PoweredOff 1 256 fromsan PoweredOff 1 256 SDK-RHAS4U4-01 PoweredOn 4 16384 onsan (1) PoweredOff 1 256 SDK-XPSP2-VC 2.0.1 PoweredOff 4 4096 SDK-WIN2003E-VC 2... PoweredOff 4 4096 Harvey-test PoweredOn 2 256 DVM333 PoweredOff 1 512 Nworks PoweredOff 1 256 NWorks-2003 PoweredOff 4 4096 Test PoweredOff 1 256 SupportVM PoweredOn 4 4096 vmname PoweredOff 1 256

PS C:\Documents and Settings\cshanklin>

Strangely there are no VMs in the VM folder, they are all in ha-folder-root 😕

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

This still feels like a bug to me Carter. Do you see this interface being improved in a future build?

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

I looked at this a bit more closely using the managed object browser and found that my vms are in fact directly attached to the vm folder and not directly attached to ha-folder-root. I agree that this is a bug and needs to be fixed in an upcoming release, and have filed a bug with development.

Carter

Reply
0 Kudos
VirtualNoitall
Virtuoso
Virtuoso
Jump to solution

Hello,

I am still not seeing how I am supposed to query for a specific subfolder and get a recursive list of virtual machines contained within.

Thanks!

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

...You can't. Carter just admitted it is a bug so we'll have to wait for their next beta to be released.

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
VirtualNoitall
Virtuoso
Virtuoso
Jump to solution

Can anyone comment on when this might be fixed? will this be in the next release and what is the timeframe for that release?

Thanks!

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi,

This will be fixed in our next release, which will be our public Beta release.

Carter

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

I used Carter's post about get-entityview and all that and attempted to adapt it to folders. It is very close to working. Maybe between all of us we can finish it up. Here is what I have:

#connect-vim -url https://mojito/sdk # replace with your VC ip or name

$VMNvc = new-object System.Collections.Specialized.NameValueCollection

$VMNvc.Add("name", "Vuln Hosts") # put folder name here

$folder = find-entityview -viewtype Folder -filter $VMNvc

  1. this loops through the the items in the childentity property (hashtable) which contains references to the VMs inside

$folder.ChildEntity | ForEach-Object {

$MoRefNvc = new-object System.Collections.Specialized.NameValueCollection

$MoRefNvc.Add("MoRef", $_.Value ) # the value property contains the Managed Object Reference for the VMs

find-entityview -viewtype VirtualMachine -filter $MoRefNvc # this is broken

}

The last line gives these errors (one for each VM in my example folder).

    • Note to VMware--these errors need some actual text to them. Smiley Happy

Find-EntityView :

At C:\DOCUME1\HROTTE1\LOCALS~1\Temp\Untitled44.ps1:8 char:17

+ find-entityview <<<< -viewtype VirtualMachine -filter $MoRefNvc

Find-EntityView :

At C:\DOCUME1\HROTTE1\LOCALS~1\Temp\Untitled44.ps1:8 char:17

+ find-entityview <<<< -viewtype VirtualMachine -filter $MoRefNvc

Find-EntityView :

At C:\DOCUME1\HROTTE1\LOCALS~1\Temp\Untitled44.ps1:8 char:17

+ find-entityview <<<< -viewtype VirtualMachine -filter $MoRefNvc

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

When you know the managed object's reference, you should use get-view rather than find-entityview. So the code becomes:

$folder.ChildEntity | ForEach-Object {

$thisVm = get-view $_

}

It appears that find-entityview actually disallows searching for objects by MO Ref. I don't believe this is unique to the Windows toolkit, but rather something deeply embedded in our web service APIs. get-view is a lot more efficient because there's no searching involved, but we certainly could have chosen more obvious ways of telling you not to use find-entityview Smiley Happy

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

VN, try this: http://communities.vmware.com/docs/DOC-2612

I ended up embedding it within a Word doc to avoid the forum editor issues. Which I hate doing because it means you have to download a document instead of viewing interactively. Oh well, maybe this will work out.

Anyway...the function Get-FolderContents works fine, thanks to Carter's last message.

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

Your attachment isn't working for me.

I'm adding whoever picked this forum software to my to-shoot list Smiley Sad

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

Wish I could blog about it, then I'd put it up on my site. Oh well, here's a paste and I've attached the doc. It's a function, so you need to put it in a .ps1 file and dot-source it (tutorial).

Script Name Get-FolderContents

Author Hal Rottenberg hal@halr9000.com

function Get-FolderContents {
	param ( 
		$FolderName = "$(throw 'Please specify Folder Name.')",
		$Server = "$(throw 'Please specify VC server name.')",
		$Credential
	)
	if ($Credential) { 
$conn = connect-vim -url https://$Server/sdk -Credential $Credential 
}
	else { $conn = connect-vim -url https://$Server/sdk }
	$output = @()
	$VMNvc = new-object System.Collections.Specialized.NameValueCollection
	$VMNvc.Add("name", $FolderName)
	$folder = find-entityview -viewtype Folder -filter $VMNvc
	$folder.ChildEntity | ForEach-Object {
		$thisVm = get-view $_
		$output += $thisVm
	}
	Write-Output $output
}

Message was edited by: halr9000 - used formatting tags "" and ""

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos