Below you will find pages that utilize the taxonomy term “PowerCLI”
Posts
PowerCLI Move-Datastore Function
Moving datastores into folders via drag/drop can be painful. In some cases vCenter does not want to allow a drag from a long list. Here is a quick function to make moving via PowerCLI a little bit easier.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Function Move-Datastore { param ( [VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl[]] $datastore = $(throw "Datastore(s) must be provided.
Posts
Convenience Functions for Connecting to Multiple vCenters
In a large environment repeatedly connecting and disconnecting from groups of vCenters can be tedious so I created some helper functions and put them in my PowerShell profile.
1 2 3 Connect-VIServerGroup lab Connect-VIServerGroup desktops Disconnect-VIServerGroup lab 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Function Connect-VIServerGroup { param ( [String]$group = $(throw "A VI server group name must be specified.
Posts
Single pane for multiple vCenter alarms
When you have multiple vCenters it can be a pain to go through each one checking for alarms. Hence the script below. You can specify the vCenters you want to connect to and it will display a nice sortable/filterable grid view of all of the triggered alarms.
# Usage .\Get-TriggeredAlarms -vCenters vc001,vc002 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 param ( [String[]]$vCenters ) Function Get-TriggeredAlarms { param ( $vCenter = $(throw "A vCenter must be specified.
Posts
Validate datastore visibility between hosts
This script will check a set of hosts and report on whether the available datastores match. The first host found becomes the reference host and the others are compared against it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 param ( [VMware.
Posts
Find LUNs Presented to Multiple Clusters
After some cluster migrations it appears that not all of the LUN presentations got cleaned up. I needed to find the LUNs that were shared by different clusters so I could determine which one they should belong to and remove access for the other cluster(s). PowerCLI to the rescue.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 param ( [VMware.
Posts
Validate Username / Password on ESX(i) Host
A simple script to validate the login credentials against an ESX(i) host. Useful when validating that the credentials are what you think they should be.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 <# .
Posts
VMware PowerCLI 5 Cmdlets by Noun
Generated using this post.
<th> Verbs </th> <td> Get,New,Remove,Set </td> <td> Get,New,Remove </td> <td> Get,New,Remove </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Copy </td> <td> Apply,Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get </td> <td> Copy,Get,New,Remove,Set </td> <td> Get,Move,Remove </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Set </td> <td> Get </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,Stop,Wait </td> <td> Get,Move,New,Remove,Set </td> <td> Dismount,Mount,Update,Wait </td> <td> Get,Remove </td> <td> Export,Get,Import,Move,New,Remove,Set,Start,Stop </td> <td> Get </td> <td> Get,New,Remove </td> <td> Get </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,New,Remove </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Connect,Disconnect </td> <td> Get,Move,New,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,Restart,Shutdown,Suspend </td> <td> Copy </td> <td> Get,Set </td> <td> Get,New,Remove </td> <td> Add,Get,Move,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get </td> <td> Get,Set </td> <td> Get </td> <td> Format,Get </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Install </td> <td> Apply,Export,Get,Import,New,Remove,Set </td> <td> Test </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Restart,Set,Start,Stop </td> <td> Get,Set,Test </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Invoke </td> <td> Get,Set </td>
Posts
PowerShell Asynchronous Job Queueing
Here is some sample code to have a variable size work queue for asynchronous jobs in PowerShell. The sample code uses Start-Job, but it was written as a skeleton to be able to run multiple PowerCLI tasks at once.
The variable length is beneficial in case the work should be split up, but there is a chance of overwhelming the system if too many concurrent jobs are started at once.
Posts
Using PowerCLI to Uninstall vCenter Extensions
After finishing a CapacityIQ evaluation we wanted to uninstall the plug-in from vCenter. VMware KB article 1025360 shows how to do this, but it requires the Managed Object Browser. Per the security hardening guide we disabled the mob so this solution would not work as given. PowerCLI to the rescue.
Here are the steps given in the original article and how they translate into PowerCLI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #1.
Posts
VMware PowerCLI 4.1.1 Cmdlets by Noun
Generated using this post.
<th> Verbs </th> <td> Get,New,Remove,Set </td> <td> Get,New,Remove </td> <td> Get,New,Remove </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Copy </td> <td> Apply,Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get </td> <td> Copy,Get,New,Remove,Set </td> <td> Get,Move,Remove </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Set </td> <td> Get </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,Stop,Wait </td> <td> Get,Move,New,Remove,Set </td> <td> Dismount,Mount,Update,Wait </td> <td> Get,Remove </td> <td> Export,Get,Import,New,Remove,Set,Start,Stop </td> <td> Get,New,Remove </td> <td> Get </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> New,Remove </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Connect,Disconnect </td> <td> Get,Move,New,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,Restart,Shutdown,Suspend </td> <td> Copy </td> <td> Get,Set </td> <td> Get,New,Remove </td> <td> Add,Get,Move,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get </td> <td> Get,Set </td> <td> Get </td> <td> Format,Get </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Install </td> <td> Apply,Export,Get,Import,New,Remove,Set </td> <td> Test </td> <td> Get,New,Remove,Set </td> <td> Get,Restart,Set,Start,Stop </td> <td> Get,Set,Test </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Invoke </td> <td> Get,Set </td>
Posts
PowerCLI Presentation from Central Ohio VMUG
Here is an introduction to PowerCli presentation I gave back in July at the Central Ohio VMware User’s Group.
Posts
VMware PowerCLI 4.1 Cmdlets Summarized by Noun
Here is the list of VMware PowerCLI cmdlets ordered by noun. I find this easier to use when I am trying to write scripts. You can locate what items you want to work with and then see the action you can take. This post contains the code used to generate the list.
<th> Verbs </th> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Copy </td> <td> Apply,Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Copy,Get,New,Remove,Set </td> <td> Get,Move,Remove </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Set </td> <td> Get </td> <td> Get,Move,New,Remove,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,Stop,Wait </td> <td> Get,Move,New,Remove,Set </td> <td> Dismount,Mount,Update </td> <td> Get,Remove </td> <td> Export,Get,Import,New,Remove,Set,Start,Stop </td> <td> Get,New,Remove </td> <td> Get </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> New,Remove </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Connect,Disconnect </td> <td> Get,Move,New,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,Restart,Shutdown,Suspend </td> <td> Copy </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Move,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Install </td> <td> Apply,Export,Get,Import,New,Remove,Set </td> <td> Test </td> <td> Get,New,Remove,Set </td> <td> Get,Restart,Set,Start,Stop </td> <td> Get,Set,Test </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Invoke </td> <td> Get,Set </td>
Posts
VMware PowerShell Get-VIHumanReadablePath
An example of how to get the human readable path of an object in the VMware SDK. This is using PowerShell and requires that PowerCLI be installed, but should be easily converted to other languages.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Function Get-VIHumanReadablePath { param ( $target ) try { if ($target.
Posts
Another Orchestrator/PowerShell hang issue
It has come to my attention that some times the scripts will still hang after using the trick from a previous post to fix an issue with standard input when running PowerShell in Orchestrator workflows. After further research there appears to be an issue with stderr hanging the scripts in a similar way to stdin. To be safe you should do something with the output from stderr (where error messages are sent).
Posts
Running PowerShell in VMware Orchestrator – updated
Updated 7/29/2010 – I have added a new follow up post this post regarding another related hanging issue. Please make sure to check it out.
This is a copy of my comment in the VMware Communities, but some times the Google search results for items in this blog show up and the ones for the communities do not.
The original problem is that PowerShell scripts hang when running them in Orchestrator.
Posts
Adding VMware PowerCLI to your standard PowerShell environment
In order to get access to PowerCLI when using another PowerShell shortcut or environment you can run the following commands which is what happens when you run the VMware provided shortcut.
1 2 3 4 5 6 # Adds the base cmdlets Add-PSSnapin VMware.VimAutomation.Core # Add the following if you want to do things with Update Manager Add-PSSnapin VMware.VumAutomation # This script adds some helper functions and sets the appearance.
Posts
PowerCLI Examples for VMUG Presentation 7/20/2010
These are some examples that I will be reviewing at an upcoming Central Ohio VMware User’s Group.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 # List all VMs Get-VM # Get one VM Get-VM ubuntu01 # Get VMs that match Get-VM ubuntu* # List VMs in a Datacenter Get-Datacenter dc001 | Get-VM # List VMs in a cluster Get-Cluster cluster001 | Get-VM # Get 2 CPU or larger VMs Get-VM | Where-Object {$_.
Posts
Export and Import Customization Specs Using PowerCLI
Here are a couple of functions to help you export and import OS customization specs in vCenter. Be aware that if you do this between vCenters or the certificate changes then you will have to set any encrypted passwords to their correct value after the import.
These functions and the standard *-OSCustomizationSpec cmdlets should allow you to replicate your customization specs between multiple vCenters fairly easily.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 Function Export-OSCustomizationSpec { param ( [string]$specName, [string]$exportFile = "$specname.