Retrieving Organizational Units

As in the "Computers and Users"-view described here, Virtualization-hosts are organized in Organizational Units. The difference is, that the objects handled in this chapter, are located underneath the folder "Virtual Environments".


Examples:


Hint: The execution of these examples requires a connected PowerShell drive.


The following example retrieves the Organizational Unit "XenServers" under "Virtual Environments":


Get-EmdbOrganizationalUnit "emdb:\rootDSE\Managed Virtual Environments\XenServers"


This code retrieves all Organizational Unit-objects below "Virtual Environments":


Get-EmdbOrganizationalUnit "emdb:\rootDSE\Managed Virtual Environments\*" -Recurse


Retrieve the Organizational Unit "Hyper-V" in the current context through its Item-ID (this ID will vary in different DSM environments):


Get-EmdbOrganizationalUnit -ItemID 99 -Recurse


Tip: the alias ID can be used instead of ItemID.


In order to retrieve the Organizational Unit "ESXServers" from the current context using the Get-Item cmdlet, the following commands can be used:


Cd "emdb:\rootDSE\Managed Virtual Environments"

Get-Item "ESXServers"


Using the Get-ChildItem cmdlet, all Organizational Unit objects under "Virtual Environments" can be retrieved like this:


Get-ChildItem "emdb:\rootDSE\Managed Virtual Environments" -Filter "SchemaTag=OU" -Recurse


Starting with PSX 3.1 there was a new option implemented when retrieving Organizational Unit objects. When specifying the SingleItemExpected-switch it is expected, that none or exactly one object is contained in the result. If the retrieval returns more than one object, an error is raised that can be caught and handled in scripts.