Automating Everything VMwarewith PowerCLI – Deep Dive
Alan Renouf, VMware, IncLuc Dekens, Eurocontrol
INF5211
#INF5211
• This presentation may contain product features that are currently under development.
• This overview of new technology represents no commitment from VMware to deliver these features in any generally available product.
• Features are subject to change, and must not be included in contracts, purchase orders, or sales agreements of any kind.
• Technical feasibility and market demand will affect final delivery.
• Pricing and packaging for any new technologies or features discussed or presented have not been determined.
Disclaimer
CONFIDENTIAL 2
Agenda
Welcome &
Technical Preview
1 2
Desired State Configuration
3
Best Practices
4
Q&A
Who are we?Alan RenoufProduct Line Manager, VMware
– vExpert– VMware Blog: http://blogs.vmware.com/PowerCLI/– Personal Blog: http://virtu-al.net/– Twitter: @alanrenouf
Luc DekensSystems Engineer, Eurocontrol Maastricht
– Personal Blog: http://lucd.info/– vExpert & PowerShell MVP– VMTN account: LucD– Twitter: @Lucd22
PowerCLI
Image Builder
vCloud Air
vCenter
ESX
Horizon Mirage
Horizon ViewSite
Recovery Manager
vCloud Director
vRealize Operations Manager
Update Manager
Storage
AutoDeploy
Hardware Information
PowerCLI – Technical PreviewOn
DemandVASANFSVAIO
PowerCLI Technical Preview
PS> Tech-Preview
• New module and product support for vRealize Operations• Even more storage management and automation with:
• vSphere Storage API Cmdlets• NFS User Cmdlets• Updated vSphere API for IO Filtering Cmdlets
• Connect and manage On-Demand resources in vCloud Air• Updated vCloud Air Cmdlets for networking• Host hardware information• Update Manager now included in core installer for simpler and quicker deployment• Updated Support for SRM 6.1• Licensing Snapin converted to Module
Report, Integrate, Automate vROPs• Full Low Level API Access
• High Level Cmdlets to cover some use cases
• Retrieve Alerts
• Change Alerts
• Retrieve Users
• Retrieve Stats
• Retrieve Recommendations
• Full vSphere relationship mapping
Note: Supported with vROPs 6.x
What’s New?
Another product covered by PowerCLI
New module and product support for vRealize Operations
Connection: Connect-OMServer , Disconnect-OMServer Alerts: Get-OMAlert, Get-OMAlertDefinition, Get-OMAlertSubType, Get-OMAlertType, Set-OMAlertRecommendations: Get-OMRecommendationResources: Get-OMResourceStats: Get-OMStat, Get-OMStatKey, Get-OMUser
vRealize Operations Cmdlets and Examples
Example PowerCLI code for some of the new vROPs cmdlets:
Retrieve a VM called Photon01 from vCenter and get its basic health information from vRealize Operations
C:\PS>Get-VM Photon01 | Get-OMResource
Retrieve metric data for Host01 from the last month aggregated on daily basis
C:\PS>Get-VMHost Host01 | Get-OMResource | Get-OMStat -Key "mem|waste" -From ([datetime]::Now.AddMonths(-1)) -IntervalType Days -IntervalCount 1 -RollupType Avg"
Find out what is wrong with Phton01 by listing the alerts related to the VM in a table
C:\PS>Get-VM Photon01 | Get-OMresource | Get-OMALert | FT -AutoSize
VROPSDEMO
11
vROPS example code
vSphere Storage API Cmdlets• Register new VASA Providers
• List registered VASA Providers
• List storage arrays managed by registered VASA providers
• Unregister VASA Providers
NFS User Cmdlets• Create NFS user accounts on ESXi Hosts
• List NFS user accounts on ESXi Hosts
• Change NFS user accounts on ESXi Hosts
• Remove NFS user accounts on ESXi Hosts
vSphere API for IO Filtering• Update a VAIO filter on a cluster
What’s New?
Updated Storage Cmdlets
Updated Storage Module
Storage Module
VSAN
VASA
SPBMVAIO
NFS
Updated Storage Cmdlets and Examples
Example PowerCLI code for some of the new Storage cmdlets:
Register a VASA provider by using the "MyCredential" credential and forcing the Storage Monitoring Service to accept the certificate of the provider.
C:\PS>New-VasaProvider -Name "MyProvider" -Credential "MyCredential" –Url "MyUrl" –Force
Create the "user1" NFS user account on the $vmhost virtual machine host and set the password to "password1“
C:\PS>New-NfsUser -VMHost $vmhost -Username "user1" -Password "password1"
Update the $filter VAIO filter and set the VIB URL to "NewVibUrl". The version of the new VIB should be higher than the existing filter version.
C:\PS>Set-VAIOFilter -Filter $filter -VibUrl "NewVibUrl"
New VASA Cmdlets : New-VasaProvider, Remove-VasaProvider, Get-VasaProvider and Get-VasaStorageArrayNew NFS User Cmdlets: New-NfsUser, Remove-NfsUser, Get-NfsUser and Set-NfsUserAdded VAIO filters Cmdlet: Set-VAIOFilter
Updated cmdlets to connect to On-Demand• Manage both On-Demand and Dedicated
Resources
• Updated OrgVDCNetwork Cmdlet to make working with On-Demand easier
• All vCloud Air cmdlets work
• Work with both On-Premesis and Cloud through the same shell
• No need to relearn how to automate your infrastructure
What’s New?
Single pane of glass CLI Management!
vCloud Air Cmdlets now work with On-Demand (vCA)
VIRTUALMACHINES
ON-PREMISESDATA CENTER
vCLOUD AIR
VIRTUALMACHINES
VIRTUALMACHINES
VIRTUALMACHINES
VIRTUALMACHINES
VIRTUALMACHINES
VIRTUALMACHINES
VIRTUALMACHINES
POWERCLI CMDLETS
vCloud AirDEMO
16
Hybrid report example code
17
Hybrid report example code - github.com/alanrenouf/vAudit-vCloudAir
Easily list Host hardware information• 2 new cmdlets
• Get-VMHostHardware lists host information
• Get-VMHostPCIDevice lists all PCI Devices
• Instantly see host serial numbers and hardware details
• Check host hardware similarity in a cluster
• Compare the results to the HCL
What’s New?
List hardware information easily!
Host hardware information
Host HardwareDEMO
20
Host hardware example code
Single installer to simplify installation• vSphere Update Manager module now included in
the core PowerCLI installer
• No more separate download and installer
• Support for multiple versions of VUM
• Backwards compatibility to VUM 5.5
Note: if using a VUM version previous to 5.5 you will need to install the VUM cmdlets separately
What’s New?
Now Included!
Update Manager now included in core installer
Desired State ConfigurationScripted Resources
DSC & vSphere• Go for PowerShell v5• What is needed ?• Pull or push ?• PS objects or classes ?• Where shall the vSphere resources be used ?• Implementation examples
– Resource definition– Resource assignment
• In practice: “Make it so!”• Complexity * Scale -gt What we can handle
24
DSC & vSphere
1. Configure LCM to Pull2. Develop scripted resource
1. Get2. Set3. Test
3. Package as Resource Module1. ZIP & checksum Pull2. DSC Resource to Dev WS
4. Test functioning
25
DSC & vSphere
26
DSC & vSphere
CONFIDENTIAL 27
DSC & vSphere
Best PracticesWorking with REST API
29
PowerShell and the REST API
• Why would I use a REST API ?• Can I do this from PowerShell ?
– PS v4: Invoke-RestMethod– Watch out: open connections limit set to 2
• Bypass: CloseConnectionGroup– JSON
• Convert built-in• DateTime objects are special
• Tools to help– Chrome – Advanced Rest Client– Fiddler
REST API DEMO
31
PowerShell and the REST API
Best PracticesRegular Expression
33
Question from the field: next suffix
• Names ending with a numeric suffix – calculate the next one– Start to use Select-String– …finally start learning RegEx
Best PracticesHow to use these API methods and properties
CONFIDENTIAL 35
TARGETED
More-Cmdlets
Get-DatastoreGet-VM
Get-View (Low Level)
HARDER TO USE FOR SYSADMINFAST
vSphere API
What is Get-View and .extensiondata?
.Net View of APIs (100% PUBLIC)
Cmdlets (High Level)
.ExtensionData Property
$spec = new-object VMware.Vim.VirtualMachineConfigSpec$spec.MemoryAllocation = New-Object VMware.Vim.ResourceAllocationInfo$spec.MemoryAllocation.Limit = -1$vm = get-view -ViewType VirtualMachine -Filter @{"Name"="VM001"}$vm.ReconfigVM_Task($spec)
Get-VM VM001 | Get-VMResourceConfiguration | `Set-VMResourceConfiguration -MemLimitMB $null
API
• Question keeps coming back• Another (quick) example: activate VDS health script• Method 1:
– API Reference• Yes, there is a logic in there!
– Follow the trail– Find the method
• Method 2: – Onyx Web Client– What do you get ?– How to use it ?
API : Method 1 – Books and Logic
<Ctrl>-F
API : Method 2
Automating Everything VMwarewith PowerCLI – Deep Dive
Alan Renouf, VMware, IncLuc Dekens, Eurocontrol
INF5211
#INF5211
Top Related