Introduction to View PowerCLI
Windows PowerShell is a command-line and scripting environment that is designed for Microsoft Windows. PowerShell uses the .NET object model and provides administrators with management and automation capabilities. As with any other console environment, you work with PowerShell by running commands, which are called cmdlets in PowerShell.
The command-line syntax for the View PowerCLI cmdlets is the same as generic PowerShell syntax. See the Microsoft documentation for more information about using PowerShell.
View includes 45 View PowerCLI cmdlets. You can use these cmdlets in conjunction with the vSphere PowerCLI cmdlets, which provide an administrative interface to the VMware vSphere product. If you have installed vSphere PowerCLI on a Connection Server instance, these cmdlets are loaded automatically when you launch View PowerCLI.
You can reference virtual machines and vCenters by ID in View PowerCLI, but you cannot pass such entries as objects. You must provide a full path to other vSphere objects such as resource pools and folders. You can use the View PowerCLI cmdlets to examine the configuration of vCenter Servers within View.
The View PowerCLI cmdlets are located in the PowershellServiceCmdlets.dll file in the directory C:\Program Files\VMware\VMware View\Server\bin. This file constitutes the VMware.View.Broker snapin. The script configuration file for the View PowerCLI cmdlets is named InitViewCmdlets.ps1, and this file is located in the Extras folder in the View installation directory. You can edit and extend the script to define cmdlet aliases, to configure the environment, or to set startup actions.
Start the PowerShell Console with View PowerCLI Loaded
You can run the View PowerCLI cmdlets directly on a View Connections Server host that has the following software installed.
View 4.5 or later
To use the View PowerCLI cmdlets to change the configuration of View, you must be logged into a View Connection Server instance as a user in a role with sufficient privileges, such as the Administrators role. If your role is a read-only role, you cannot update configuration data. For more information, see the VMware Horizon View Administration document.
To start the PowerShell console with View PowerCLI loaded
1
Select Start > All Programs > VMware > View PowerCLI.
2
If you see an error message stating that the script configuration file cannot be loaded because the execution of scripts is disabled, type the following PowerShell command and restart the PowerShell console.
Set-ExecutionPolicy Unrestricted
Accessing View PowerCLI cmdlets from a Remote System
If you use the PowerShell remoting feature to access the View PowerCLI cmdlets from a remote system, be sure to take the same precautions for protecting the View PowerCLI operations that you would take for other remoting PowerShell operations.
You can add the View PowerCLI snapin to the Powershell profile on the remote system so that you do not have to load and initialize the View PowerCLI snapin each time you restart the system.
To add the View PowerCLI snapin to the Powershell profile
1
On the remote system, open the following file: C:\Windows\System32\WindowsPowerShells\v1.0\Profile.ps1
2
add-pssnapin vm*
Displaying Help for a View PowerCLI cmdlet
To list all View PowerCLI cmdlets, type this command in the PowerShell console.
Get-Command -PSSnapin VMware.View.Broker | more
You can get help for a specific cmdlet by using the Get-Help cmdlet in the PowerShell console. For example, to get help on the Add-ViewVC cmdlet.
Get-Help Add-ViewVC | more
For more detailed information, add the -full parameter.
Get-Help Add-ViewVC -full | more
Alternatively, you can use the help alias for Get-Help.
help Add-ViewVC -full | more
Error Handling
View PowerCLI cmdlets handle all errors as non-terminating errors that halt the execution of a cmdlet but do not terminate a pipeline. You can examine the $error automatic variable to determine the nature of an error. You can set the standard PowerShell $ErrorActionPreference and $errorView automatic variables to control how PowerShell handles non-terminating errors and how it displays them in the shell.
Error When Piping and Specifying Objects at the Same Time
If you attempt to pipe an object into a cmdlet and specify an object of the same type to that cmdlet, the cmdlet fails with the following error.
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
For example, the following cmdlet usage would produce this error.
Get-Pool -pool_id Pool1 | Update-ManualPool -pool_id Pool2 -displayName “Manual Pool 2”
Escaping Characters in vCenter Path Names
If you specify a path to a vCenter folder that includes certain special characters in the name of an entity, you must escape these characters. Escape Sequences for Special Characters shows the escape sequences for special characters.
Do not escape the slashes in the path name itself. For example, you would represent the path to the folder /datacenter_01/vm/img%-12 as /datacenter_01/vm/img%25-12.
Cmdlet Parameters Requiring Escape Sequences lists the cmdlets and parameters that require you to use escape sequences in entity names.