This is not going to be an exhaustive tutorial on how to completely replace the vSphere GUI – but if you were inclined to do so, this would be a way to start.
This “starter” eventually went on to become a fully fledged VMware GUI task orchestrator (a topic for a future post, perhaps).
This script will enumerate all of your VM folders (and the VMs therein) and correctly display them in a Treeview. It doesn’t sound like much, but from there you can use “on click” listeners to display info for a specific VM when it’s selected, make changes to VMs, and lots more.
After opening PowerCLI and connecting to your vCenter server, you can just copy/paste the below script.
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 |
# Function to recurse VM Folders - called later in the script function getchildren ($parentid, $parentname, $parentnode) { # Get sub-folders of current parent folder $childfolders = $folders | where {$_.parentid -eq $parentid}; # If sub-folders are found, loop though them if ($childfolders) { foreach ($childfolder in $childfolders) { # Add a new node to the Treeview with the correct name and ID $childnode = New-Object System.Windows.Forms.TreeNode $childnode.text = $childfolder.name; $childnode.name = $childfolder.id; [void]$parentnode.Nodes.Add($childnode) # Recurse getchildren $childfolder.id $childfolder.name $childnode; } } # Get VMs in this folder $foldervms = $vms | where {$_.folderid -eq $parentid} | sort name; # Loop through and add each VM as a child to the current folder in the Treeview foreach ($vm in $foldervms) { $childnode = New-Object System.Windows.Forms.TreeNode $childnode.text = $vm.name; $childnode.name = $vm.id; [void]$parentnode.Nodes.Add($childnode); } } # Main starts here [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing"); [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms"); # Get all datacenters and all VMs $datacenters = get-datacenter; $vms = get-vm; # Set form size, background, font, window title $form = new-object System.Windows.Forms.Form; $form.size = new-object System.Drawing.Size(600 ,400); $form.font = new-object System.Drawing.Font("Arial",9,[System.Drawing.FontStyle]::Regular); $form.backColor = "#B2B3BF"; $form.text = "Test Form"; # Create the Treeview and add to the form $treeView1 = new-object System.Windows.Forms.TreeView; $treeView1.location = new-object System.Drawing.Point(48, 12); $treeView1.size = new-object System.Drawing.Size(290, 322); $form.controls.add($treeView1); # Loop through each datacenter found foreach ($datacenter in $datacenters) { # Get all folders in the current datacenter $folders = $datacenter | get-folder; # Loop through each folder foreach ($folder in $folders) { # Limit scope to VM folders only if ($folder.name -eq "vm") { # Call function to get child folders getchildren $folder.id $folder.name $treeview1; } } } # Display the form [System.Windows.Forms.Application]::EnableVisualStyles(); $form.Add_Shown({$Form.Activate()}); [void] $form.ShowDialog(); |
Assuming you have grouped your VMs into a folder hierarchy, a form should display that looks something like this: