# Some Basic Powershell Get-Help Get-Command Get-Service Get-Help Get-Service -Full Get-Help Get-Service -Example Get-Service | Get-Member Get-Service | Select-Object Name, Status, MachineName Get-Service | where {$_.status -eq "Running" } # --- VI Toolkit --- # List all VI Toolkit related cmdlets Get-VICommand #Get help for the VI Toolkit cmdlets Get-Help Get-VM -Full Get-Help Get-VM -Example # Connect to the Virtual Infrastructure Server - Could be a host Connect-VIServer VC # Get a list of VMs Get-VM # See the details of the Get-VM Object returned Get-VM | Get-Member # How many VMs do we have in our VI (Get-VM).Count # Get a List of our hosts Get-VMHost # Which guests are on our particular host Get-VMHost ESX01.virtual.net | Get-VM # Create a new VM on our host Get-VMHost ESX01.virtual.net | New-VM -Name "NewVm0" -DiskMB 1 -MemoryMB 128 # Create 5 new vms on our host Foreach ($i in 1..5) { Get-VMHost ESX01.virtual.net | New-VM -Name "Newvm$i” -DiskMB 1 -MemoryMB 128 } # change one of our newly created VMs to have 2 CPUs Get-Vm Newvm1 | set-vm -NumCpu 2 -confirm:$false # Export our Guests to a CSV File Get-VM | Export-CSV C:\UKVMUG\AllVMs.csv # Open the CSV using Invoke-Item Invoke-Item c:\ukvmug\allvms.csv # Export our Guests to a HTML File Get-VM | ConvertTo-Html > C:\UKVMUG\AllVMs.html # Open the HTML file using Invoke-Item Invoke-Item c:\ukvmug\allvms.html # Disconnect any CD-ROM Drives Get-VM | Get-CDDrive | Set-CDDrive -Connected $false –confirm:$false # Delete our VMs we just created Remove-VM New* -confirm:$false # List our hosts and there Service console details Get-VMHost esx01.virtual.net | Get-vmhostnetwork # List virtual switches on our hosts Get-VMHost | Get-VirtualSwitch # List portgroups on our hosts Get-VMHost | Get-VirtualSwitch | Get-VirtualPortGroup # Create a portgroup on our host Get-VirtualSwitch -VMHost ESX01.virtual.net -Name 'vSwitch0' | New-VirtualPortGroup -Name 'Production Network' -VLanId 100 # Delete our newly created portgroup Get-VirtualSwitch -VMHost ESX01.virtual.net -Name 'vSwitch0' | Get-VirtualPortGroup -Name "Production Network" | Remove-VirtualPortGroup # List All Datastores Get-vmhost | get-datastore # List all clusters Get-Cluster # Rescan storage on each of the hosts - VERY USEFUL Get-VMHost | Get-VMHostStorage -RescanAllHba # Create a Snapshot for W2K3 Get-VM W2K3 | New-Snapshot -Name Snapshot1 # List all Snapshots for all VMs Get-VM | Get-Snapshot # Get it ready for VESI Demo Foreach ($i in 1..5) { Get-VMHost ESX01.virtual.net | New-VM -Name "Newvm$i” -DiskMB 1 -MemoryMB 128 } # Accessing the full objects Get-VM | Get-View # What more does this give us ? Get-VM | Get-Member Get-VM | Get-View | Get-Member #Cleanup Remove-VM New* -confirm:$false Get-VM | Get-Snapshot -Name Snapshot1 | Remove-Snapshot -confirm:$false Remove-item c:\UKVMUG\allvms.csv Remove-item c:\UKVMUG\allvms.html