Information Technology Reference
In-Depth Information
Manipulating Virtual Machine Snapshots
Let's look at a second example of how to use PowerCLI in your VMware vSphere environment.
In this example, you'll use PowerCLI to work with VM snapshots.
Let's say that you need to perform an application upgrade for a system with multiple servers.
It may be useful to create a snapshot for all the VMs associated with that application, which you
have organized in a vCenter inventory folder. This one-liner would accomplish that task for you:
Get-Folder <Folder Name> | Get-VM | New-Snapshot -Name ″Pre-Upgrade″
If you later needed to remove the snapshot you created, you could use the Remove-Snapshot
cmdlet to delete it:
Get-Folder <Folder Name> | Get-VM | Get-Snapshot -Name ″Pre-Upgrade ″ |`
Remove-Snapshot
Finally, you could use the Get-Snapshot cmdlet to list all snapshots so that you could be sure
you had actually created or deleted them:
Get-Folder <Folder Name> | Get-VM | Get-Snapshot
This command would return a list of any snapshot objects for all the VMs in the specii ed
folder.
Reconfiguring Virtual Machine Networking
In this third example, let's say that you want to move all the VMs currently connected to
one port group to an entirely different port group. This is actually possible with a one-
line command in PowerCLI:
Get-VM | Get-NetworkAdapter | Where-Object {$_.NetworkName -like `
″OldPortGroupName″} | Set-NetworkAdapter -NetworkName ″NewPortGroupName″`
-Confirm:$false
There are a few of the new ideas introduced here, so let us break it down a little bit:
The Get-VM cmdlet retrieves VM objects.
These VM objects are passed to the Get-NetworkAdapter cmdlet, which returns virtual
NIC objects for all VMs.
These virtual NIC objects are parsed using the Where-Object cmdlet to include only those
virtual NICs whose NetworkName property is like the ″OldPortGroupName″ string.
The parsed list of virtual NICs is passed to the Set-NetworkAdapter cmdlet, which sets
the NetworkName property to the ″NewPortGroupName″ value.
The Confirm parameter instructs PowerShell to not ask the user for coni rmation of each
operation.
Moving Virtual Machines between Resource Pools
In this last example, you'll use PowerCLI to move a group of VMs from one resource pool to
another. However, you want to move only a subset of the VMs in this resource pool. Only the
VMs that are running a Microsoft Windows guest operating system (guest OS) should be moved
to the new resource pool.
Search WWH ::




Custom Search