Examples of Using View PowerCLI Cmdlets
The View PowerCLI cmdlets allow you to perform View operations from the command line or from scripts instead of using View Administrator. The following sections contain examples that you can adapt and apply to your own systems.
Displaying Information About a View Connection Server Instance
Display the configuration settings of a View Connection Server instance.
Get-ConnectionBroker -broker_id CONNSVR1
Updating the Configuration of a View Connection Server Instance
Update the settings for direct connections and secureID on a View Connection Server instance.
Update-ConnectionBroker -broker_id CONNSVR1 -directConnect $false -secureIdEnabled $true -ldapBackupFrequency EveryWeek
Configure a View Connection Server for secure PCoIP connections.
Update-ConnectionBroker -broker_id CS-VSG -directPCoIP $FALSE
Set the PCoIP external URL for a View Connection Server.
Update-ConnectionBroker -broker_id CS-VSG -externalPCoIPURL 10.18.133.34:4172
Set the PCoIP external URL for a security server.
Update-ConnectionBroker -broker_id SECSVR-03 -externalPCoIPURL 10.116.32.136:4172
Managing the Configuration of vCenter Servers in View
Add an entry for a vCenter Server to the View configuration.
Add-ViewVC -serverName vc01.mydom.int -username Administrator -password clydenw -createRampFactor 5 -deleteRampFactor 5
Return information about a vCenter Server.
Get-ViewVC -serverName vc01.mydom.int
Return information about all vCenter Servers in a specified DNS domain.
Get-ViewVC -serverName *.mycorp.com
Change the values of the ramp factors for the vCenter Server that is configured on server svr11.
Get-ViewVC -serverName svr11.mycorp.com | Update-ViewVC -createRampFactor 5 -deleteRampFactor 10
Change the value of the create ramp factor for the vCenter Servers that are configured in the DNS domain mycorp.com.
Get-ViewVC -serverName *.mycorp.com | Update-ViewVC -createRampFactor 5
Remove an entry for a vCenter Server from the configuration.
Get-ViewVC -serverName vc02.mydom.int | Remove-ViewVC
Managing Desktop Pools
Return information about the desktop pool with a specified display name.
Get-Pool -displayName "My Pool 1"
Return information about all desktop pools with the prefix mypool-.
Get-Pool -pool_id mypool-*
Return information about all desktop pools that are configured to use the PCoIP protocol.
Get-Pool -protocol PCOIP
Return information about all individual unmanaged desktop pools.
Get-Pool -poolType IndividualUnmanaged
Remove the desktop pool dtpool-10.
Remove-Pool -pool_id dtpool-10
Remove the desktop pool dtpool-12, terminating any active session, but without deleting the image from disk.
Remove-Pool -pool_id dtpool-12 -TerminateSession $true -DeleteFromDisk $false
Remove a desktop pool specified by its display name, and delete its image from disk.
Get-Pool -displayName "My Pool 1" | Remove-Pool -DeleteFromDisk $true
Creating and Updating Automatically Provisioned Desktop Pools
Add the automatically provisioned desktop pool auto1, which is managed by the vCenter Server vc.mydom.int.
Get-ViewVC -serverName vc.mydom.int | Add-AutomaticPool -pool_id auto1 -displayName "ADP1" -namePrefix "adp1-{n:fixed=4}" -vmFolderPath /AutoConfig/vm -resourcePoolPath /AutoConfig/host/Resources -templatePath /AutoConfig/vm/ADP_template -dataStorePaths /host/datastore_1/lun10 -customizationSpecName "Windows 7 Variation 3" -minimumCount 4 -maximumCount 10
Note To provision all the desktops in advance of their use, set -minimumCount and -maximumCount to the same value.
Update the configuration of the automatically provisioned desktop pool auto1.
Update-AutomaticPool -pool_id auto1 -displayName "Automatic Desktop Pool 1" -isProvisioningEnabled $false -dataStorePaths /host/datastore_1/lun10;/host/datastore_1/lun12
The datastores that you specify as arguments to -datastorePaths override the previous setting. You must specify the existing datastores to retain them for use by the pool.
Creating and Updating Linked-Clone Desktop Pools
Add the linked-clone desktop pool lcdpool_1, which is managed by View Composer on the vCenter Server vc.mydom.int.
Get-ViewVC -serverName vc.mydom.int | Get-ComposerDomain -domain VCDOM | Add-AutomaticLinkedCLonePool -pool_id lcdpool_1 -displayName "LCD Pool 1" -namePrefix "lcp1-{n}-dt" -parentVMPath /AutoPoolVMs/parent -parentSnapshotPath /AutoPoolSnapshots/parent1_snapshot -vmFolderPath /AutoConfig/VM_folder -resourcePoolPath /AutoConfig/host/Resources -datastoreSpecs [Aggressive,os,data]/host/datastore_1/lun04;/host/datastore_2/lun16 -dataDiskLetter "D" -dataDiskSize 100 -minimumCount 4 -maximumCount 10
Note To provision all the desktops in advance of their use, set -minimumCount and -maximumCount to the same value.
If you specify a persistent data disk, use an uppercase letter for the drive. Do not use a letter that already exists on the parent virtual machine for a drive such as A, B, or C, or that conflicts with a network-mounted drive.
Update the configuration of the linked-clone desktop pool lcdpool_1.
Get-ViewVC -serverName vc.mydom.int | Get-ComposerDomain -domain VCDOM | Update-AutomaticLinkedCLonePool -pool_id lcdpool_1 -datastoreSpecs [Conservative,os,data]/host/datastore_1/lun04;/host/datastore_2/lun16;/host/datastore_2/lun22 -minimumCount 4 -maximumCount 20 -headroomCount 2 -powerPolicy Suspend -defaultProtocol PCOIP -isUserResetAllowed $true
The datastores that you specify as arguments to -datastoreSpecs override the previous setting. You must specify the existing datastores to retain them for use by the pool.
Rebalance desktops in the linked-clone desktop pool lcdpool_2 among the available datastores.
Get-DesktopVM -pool_id lcdpool_2 | Send-LinkedCloneRebalance -schedule 2011-05-10:01:00:00 -forceLogoff $false -stopOnError $true
Refresh the operating system disk of each linked-clone desktop by restoring it to its original state and size.
Get-DesktopVM -pool_id lcdpool_2 | Send-LinkedCloneRefresh -schedule "May 12 2011 01:15" -forceLogoff $true -stopOnError $true
Recompose all linked-clone desktops from a snapshot of their parent virtual machine.
Get-DesktopVM -pool_id lcdpool_2 | Send-LinkedCloneRecompose -schedule ((Get-Date).AddHours(8)) -parentVMPath /AutoPoolVMs/parent2 -parentSnapshotPath /AutoPoolSnapshots/parent2_snapshot -forceLogoff $true -stopOnError $true
Creating and Updating Manually Provisioned Desktop Pools
Create a manually provisioned desktop pool that contains the virtual machine myVM. To use the Get-VM cmdlet, you must install vSphere PowerCLI.
Add-ManualPool -pool_id manPool -id (Get-VM -name "myVM").id -isUserResetAllowed $true
Create the manually provisioned desktop pool man1 from the desktops listed by the vCenter Server vc.mydom.int.
Get-ViewVC -serverName vc.mydom.int | Get-DesktopVM -poolType Manual | Add-ManualPool -pool_id man1 -isUserResetAllowed $false
Update the configuration of the manually provisioned desktop pool man1.
Update-ManualPool -pool_id man1 -displayName "Manual Desktop 1" -isUserResetAllowed $true
Creating Manual Unmanaged Desktop Pools
Create the unmanaged desktop pool unman1 that contains the physical machines pm01 and pm02.
Add-ManualUnmanagedPool -pool_id unman1 -pm_id_list pm01;pm02 -isUserResetAllowed $true
Update the configuration of the unmanaged desktop pool unman1.
Update-ManualUnmanagedPool -pool_id unman1 -displayName "Unmanaged Desktop 1" -isUserResetAllowed $false
Creating and Updating Desktops Provisioned by Terminal Servers
Return information about a terminal server.
Get-TerminalServer -hostname tsvr01
Add the desktop pool tsd1 using a machine that is provided by the terminal server at a specified IP address.
Get-TerminalServer -hostname tsvr01 | Add-TerminalServerPool -pool_id tsd1 -displayName "Terminal Server Desktop 1" -allowProtocolOverride $true
Update the configuration of the desktop pool tsd1, which uses a machine provided by a terminal server.
Get-TerminalServer -hostname tsvr01 | Update-TerminalServerPool -pool_id tsd1 -displayName "Terminal Server Desktop 1" -allowProtocolOverride $false -autoLogoffTime 1
Obtaining Information About Users and Groups from Active Directory
Return information about users in the domain mydom.
Get-User -domain "mydom"
Return information about the user fred in the domain mydom and exclude any information about the user’s group.
Get-User -name "fred" -domain "mydom" -includeGroup $false
Managing Desktop Entitlements
Add an entitlement for the user fred in the domain mydom to use desktop pool dtop-12.
Get-User -name "mydom\fred" | Add-PoolEntitlement -pool_id dtop-12
Add an entitlement to all desktop pools for the user usr1.
Get-Pool | Add-PoolEntitlement -sid (Get-User -name "usr1").sid
Return information about all entitlements to desktop pools.
Get-PoolEntitlement
Return information about the users who are entitled to use desktop pool dtop-1.
Get-PoolEntitlement -pool_id dtop-1
Return information about the users who are entitled to use desktop pools whose IDs start with dtpool-.
Get-Pool -pool_id dtpool-* | Get-PoolEntitlement
Remove the entitlement to use desktop pool dtpool-11.
Get-PoolEntitlement -pool_id dtpool-11 | Remove-PoolEntitlement
If you want to remove all entitlements from the system, specify the -forceRemove parameter set to $true .
Get-PoolEntitlement | Remove-PoolEntitlement -forceRemove $true
If you do not specify the-forceRemove parameter, you can use the command to find out information about the entitlements that would be removed.
Managing Local Desktops
Return information about the local desktop vmcn11.
Get-LocalSession -machine_id (Get-DesktopVM -Name "vmcn11").machine_id
Roll back the local desktop.
Send-LocalSessionRollback -machine_id (Get-DesktopVM -Name "vmcn11").machine_id
Managing Remote Sessions
Return the list of active remote sessions for the user fred in the domain mydom.
Get-RemoteSession -username mydom\fred
Disconnect the active remote sessions on which the user fred is logged in.
Get-RemoteSession -username mydom\fred | Send-SessionDisconnect
Log out the active remote sessions on which the user fred is logged in.
Get-RemoteSession -username mydom\fred | Send-SessionLogoff
Log out the active remote sessions that are using the RDP protocol.
Get-RemoteSession -protocol RDP | Send-SessionLogoff
Managing Virtual Machines
Return information about the virtual machine for the desktop pool dtpool-3.
Get-DesktopVM -pool_id dtpool-3
Return information about the virtual machines that are configured on the vCenter Server vc03.local.int.
Get-DesktopVM -vc_id (Get-ViewVC -serverName vc03.local.int).vc_id
Return information about the virtual machines that are managed by the same vCenter Server that provisions the desktop pool dtpool-1.
Get-ViewVC -pool_id dtpool-1 | Get-DesktopVM
Return information about all virtual machines that are managed by the vCenter Server that is configured on the server vc01.mydom.int.
Get-ViewVC -serverName vc01.mydom.int | Get-DesktopVM
Return a list of active persistent user data disks for the virtual machine vm01.
Get-ProfileDisk -VMname vm01
Reset the virtual machines for the desktop pool dtpool-05.
Get-Pool -pool_id dtpool-05 | Get-DesktopVM | Send-VMReset
Reset the virtual machine for the desktop pool with the display name dtp1.
Get-Pool -displayName dtp1 | Get-DesktopVM | Send-VMReset
Displaying Information About Physical Computers
Return information about the computer at a specified IP address.
Get-DesktopPhysicalMachine -hostname myhost01
Updating the Ownership of Machines
Update the ownership of the virtual machine vm04 to the user usr1.
Update-UserOwnership -machine_id (Get-DesktopVM -Name "vm04").machine_id -sid (Get-User -name usr1).sid
Remove the ownership of a virtual machine.
Remove-UserOwnership -machine_id (Get-DesktopVM -Name "vm22").machine_id
Displaying Information About Events
Display the views that are available for reporting events.
Get-EventReportList
Display configuration change events that have occurred since the specified date.
Get-EventReport -viewName config_changes -startDate (Get-Date -Year 2011 -Month 5 -Day 20 -Hour 0 -Minute 0 -Second 0)
Display user events that occurred between two specified dates.
Get-EventReport -viewName user_events -startDate (Get-Date -Year 2011 -Month 12 -Day 1 -Hour 0 -Minute 0 -Second 0) -endDate (Get-Date -Year 2011 -Month 12 -Day 2 -Hour 0 -Minute 0 -Second 0)
Display user events for the last 24 hours.
Get-EventReport -viewName user_events -startDate ((Get-Date).AddDays(-1))
Display user events for the current year.
Get-EventReport -viewName user_events -startDate (Get-Date -Day 01 -Month 01 -Hour 0 -Minute 0 -Second 0)
Managing the Global Configuration of View
Display the global configuration settings.
Get-GlobalSetting
Set the session timeout to 30 minutes.
Update-GlobalSetting -SessionTimeout 1800
Note The -SessionTimeout value is measured in seconds. In View Administrator, the Session timeout value is measured in minutes. If View PowerCLI generates a value that is less than 60 seconds, View Administrator rounds down, resulting in a value of 0. To set a session timeout in View PowerCLI, specify a -SessionTimeout value of 60 (one minute) or greater.
Set the forced logout warning message and delay period.
Update-GlobalSetting -DisplayLogoffWarning $true -ForcedLogoffAfter $logoutdelay -ForcedLogoffMessage "Forced log out will occur in $logoutdelay minutes"
Require clients to use SSL to connect and set the prelogin message.
Update-GlobalSetting -UseSSLClient $true -PreLoginMessage "Insert disclaimer and other notices here."
Managing View Licenses
Display the installed View license keys.
Get-License
Add a license key.
Set-License -key "08A25-0212B-0212C-4D42E"