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!
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
I get the same behavior. A bug perhaps.
wow, this is pretty basic. I know this isn't yet ready for release but this is pretty fundamental stuff.
We do a lot of reporting so this pretty much kills powershell for us for a bit
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
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 -
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) -
PS C:\Documents and Settings\cshanklin>
Strangely there are no VMs in the VM folder, they are all in ha-folder-root 😕
This still feels like a bug to me Carter. Do you see this interface being improved in a future build?
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
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!
...You can't. Carter just admitted it is a bug so we'll have to wait for their next beta to be released.
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!
Hi,
This will be fixed in our next release, which will be our public Beta release.
Carter
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
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.
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
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
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.
Your attachment isn't working for me.
I'm adding whoever picked this forum software to my to-shoot list
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 ""