PowerCLI 101

Download Report

Transcript PowerCLI 101

VSP1361
VMware vSphere PowerCLI 101
Name, Title, Company



Save Time
Reduce Risk
Scale




Introduction to PowerShell
vCenter management
Storage management
Automating VM lifecycle



Cmdlet (pronounced command-lets) are
compiled .NET class that perfom a single
action on an object. They are named in the
<verb>-<singular noun> format.
Objects: A collection of properties and
methods with a unique type name.
Pipeline: Passes whole .NET objects from one
cmdlet to another enabling clean powerful
syntax.
PowerShell Pipeline
Format-Table
Start-VM
Where-Object
Get-VM
Get-VM | Where-Object {$_.PowerState –eq ‘Powered Off’} | Start-VM | Format-Table





Get-Command
Get-Help
Get-Module
Get-Member
Format-List
Live Demo
Needs & Environment
Tasks:
• Create new datacenter
• Add existing Host and VMs to new vCenter instance.
• Create a new cluster
• Add new Host to the new cluster
Cmdlets used:
• Connect-VIServer
• New-Datacenter
• Add-VMHost
• New-Cluster
• Set-Cluster
• Move-VMHost
# Add host to vCenter
Connect-VIServer vCenter01.sea-tm.netapp.com
# Create Datacenter
$Datacenter = New-Datacenter -Name Bellevue -Location (Get-Folder)
# Add the first host
Add-VMHost -Name vSphere1.sea-tm.netapp.com -Location $Datacenter `
-Force
# Create new cluster
$Cluster = New-Cluster -Name VMworld -Location $Datacenter
# Set the HA/DRS Settings for our cluster
Set-Cluster -cluster $Cluster -HAEnabled $True `
-HAIsolationResponse DoNothing -DrsEnabled $True -Confirm:$false
# Move our existing host into the new cluster
Move-VMHost -VMHost vSphere1* -Destination $Cluster
# Add an additional host to the cluster
Add-VMHost -Name vSphere2.sea-tm.netapp.com -Location $Cluster `
-Force -RunAsync
Live Demo
Needs & Environment
Tasks:
• Find and remove any large snapshots.
• Provision new storage on Array
• Add datastore to hosts
• Move VMs to new storage.
Cmdlets used:
• Get-VM
• Get-Snapshot
• Get-VMHost
• New-Datastore
• Sort-Object
• Format-Table
• Remove-Snapshot
• Set-NaQtree
• Set-NaNfsExport
•
•
•
•
•
•
•
•
Move-VM
Get-Datastore
ConnectNaController
New-NaVol
Set-NaSis
Enable-NaSis
Start-NaSis
Get-NaQtree
# Find any large snapshots.
Get-VM|Get-Snapshot|Sort-Object SizeMB -Descending |Format-Table VM,Name,SizeMB
# Delete that sucka!
Get-Snapshot -VM SQL01 -Name updates | Remove-Snapshot -RunAsync
# we're still a little tight... Create a new datastore!
# Import the NetApp DataONTAP PowerShell Toolkit
Import-Module DataONTAP
# Connect to the NetApp Controller
Connect-NaController 10.58.92.213
# Create a new volume, and configure dedupe
New-NaVol -Name vmdata1 -Aggregate aggr1 -SpaceReserve none -Size 10t |
Set-NaSis -Schedule auto | Enable-NaSis | Start-NaSis | Get-NaQtree |
Set-NaQtree -SecurityStyle unix
# Create the NFS export
Set-NaNfsExport -Persistent -Path /vol/vmdata1 -Root '172.16.3.0/24' `
-ReadWrite '172.16.3.0/24'
# Add datastore
Get-Cluster VMworld | Get-VMHost | New-Datastore -Name vmdata1 -Nfs `
-Path /vol/vmdata1 -NfsHost 172.16.3.213
# Move a VM to make some more room in our oversubscribed datastore.
Get-VM Exch* | Move-VM -Datastore (Get-Datastore vmdata1) -RunAsync
Live Demo!
Needs & Environment
Tasks:
• Clone an existing VM.
• Create a new VM.
• Convert VM to VM Template.
• Deploy multiple VMs from Template.
• Delete a VM.
Cmdlets used:
• Get-Cluster
• Get-Datacenter
• Get-VM
• Get-VMHost
• New-VM
• Remove-VM
• Set-VM
• ForEach-Object
# We'll use this more than once!
$vmhost = Get-Cluster -Name VMworld | Get-VMHost | Select -first 1
# Clone a VM for the ops team to test a patch.
New-VM -Name SQL03_Clone -VM SQL03 -VMHost $VMHost -RunAsync
# Create a new VM
$VM = New-VM -Name "AwesomeVM01" -VMHost $vmhost -DiskMB 61440 `
-MemoryMB 4196
# Now Make a template of that fool
$template = $VM | Set-VM -ToTemplate -Name "VMworld Template"
# Add a force multiplier
1..6| ForEach-Object {
New-VM -Name "VM$_" -Template $template -VMHost $vmhost -RunAsync
}
# Cleanup old VM
Get-VM SQL03_Clone | Remove-VM -DeletePermanently
Books:
• Learn Windows PowerShell in a Month of Lunches
• VMware vSphere PowerCLI Reference
Blogs:
• http://www.lucd.info/
• http://www.virtu-al.net/
Forums:
• http://www.vmware.com/go/PowerCLI
• http://powershellcommunity.org
• http://social.technet.microsoft.com/Forums/en/ITCG/threads
Twitter: Use the hashtag #PowerShell #PowerCLI to get help.