providence vmug - powercli

28
Providence VMUG PowerCLI Jonathan Frappier, @jfrappier www.virtxpert.com

Upload: jonathan-frappier

Post on 19-Nov-2014

531 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Providence VMUG - PowerCLI

Providence VMUG

PowerCLIJonathan Frappier, @jfrappier

www.virtxpert.com

Page 2: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

• Who am I (aka why you should listen to me)• Why automate?• Why PowerCLI?• PowerCLI 101: Get-AllTHEcmdlets!• Combining PowerCLI cmdlets into scripts• Live demo (because that’s always a good idea)• Next steps challenge• Community resources• Q&A

Page 3: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Who am I?• 15+ Years in technology• VMware Certified Advanced Professional – Data Center

Design (VCAP5-DCD)• EMC Proven Cloud Infrastructure and Services

(EMCCIS)• Community dude – Twitter, blogger, podcaster

@vbrownbag, VMware vExpert 2013-2014, EMC Elect 2014

• Author

• I have struggled with automation, I have struggled with business that didn’t understand the value, I taught those companies why automation was important

Page 4: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Why automate?• NOT a time saver…at first

Page 5: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Why automate?Automation is the path to ITaaS.

Automation enables Standardization, Standardization leads to Security

Page 6: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Why automate?1. Understand business requirements

2. Documentation

3. Standardization

4. Automation

5. Security

Page 7: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Why PowerCLI?

Page 8: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Page 9: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Why PowerCLI?• Free, extremely powerful tool with over 370 cmdlets• Ability to control installation, management and configuration

of vSphere components (vSphere, vCenter, ESXi, Networking, Storage, VMs), vCloud Director, VMware View

• Designed for system administrators, low learning curve• Important tool used for custom ESXi images and Auto

Deploy• Use seamlessly with standard Windows PowerShell

cmdlets/functions• Many community resources• Did I mention free?

Page 10: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Why PowerCLI - Example

• Even basic vSphere tasks can be a very lengthy process

• Creating a new VM requires ~ 33 mouse clicks

• 1 line in PowerCLI can do the same thing as 33 mouse clicks!

Page 11: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Get-Started (not a real cmdlet)• On 64-bit systems, launch PowerShell and PowerShell x86

consoles and run– Set-ExecutionPolicy RemoteSigned

• New- & Set-OSCustomizationSpec cmdlets are 32-bit only• Run PowerShell and PowerCLI as Administrator (even if you are an

administrator)

Page 12: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

PowerCLI 101 – Get cmdlets• Allows you to retrieve information (e.g. “get”)• If you remember only 1 Get cmdlet, make it Get-Help Get-*• You use Get-Help to get information about a specific cmdlet: Get-

Help Get-VM (-examples)

Page 13: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

PowerCLI 101 – Example - Get-VMHost

Page 14: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

PowerCLI 101 – Display Output• Format-Wide, Format-List, Format-Table (Default)

Page 15: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

PowerCLI 101 – Filtering• Select-Object (select)

– Get-VMHost | Get-VMHostNetworkAdapter | Select-Object Mac

• Where-Object– Get-VMHost | Get-VMHostNetworkAdapter | Where-Object –eq

Mac– -eq, -like, -contains, -notcontains, -gt, -ge, -lt, -le

• Out-GridView– Get-VMHost | Get-VMHostNetworkAdapter | Out-GridView

Page 16: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

PowerCLI 101 – Set cmdlets• Allows you to configure settings (e.g. “set”)• If you remember only 1 Get cmdlet, make it Get-Help• Most (All?) Get cmdlets have a corresponding Set cmdlet• In many cases you need to Get something before you can Set

something

Page 17: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

PowerCLI 101 – Example

Set-VMHostNetworkAdapter• In many cases you need to Get something before you can Set

something– Get-VMHost host | Get-VMHostNetwork Adapter –VMKernel | Set-

VMHostNetworkAdapter parameters

Page 18: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

PowerCLI 101-whatif• Allows you to see the result of running a cmdlet or script• Useful for testing

Page 19: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

PowerCLI 101Add-, New-, Remove- cmdlets• Add-VMHost – Adds a host to be managed by vCenter• Add-VMHostNtpServer – Adds the specified NTP server to ESXi• New-Cluster – Creates a new cluster• New-VM – Creates a new VM• Remove-Cluster – Removes the cluster• Remove-VM – Removes the VM from vCenter

Page 20: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

What is wrong with this command?

Page 21: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Why PowerCLI – Prompt for Input

Instead of:

You can ask for user input:

Page 22: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Why PowerCLI – Read from CSV

Instead of:

You can provide data in a CSV:

Reference post from Sebastian Barylo via www.vmwaremine.com http://goo.gl/cRlbwp

Page 23: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Page 24: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Tips• #Comment #Everything #Hashtag• Use full cmdlets (e.g. Select-Object instead of Select)• Indent, Indent, Indent (This is for you Kanji)

– Indent once after every bracket– De-indent(?) after every closed bracket

• PowerShell console shortcuts:– http://technet.microsoft.com/en-us/magazine/ff678293.aspx

Page 25: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Next steps challenge• Keep PowerCLI open, start with Get-Cmdlets• Review the vSphere Hardening Guide ~100 PowerCLI

examples for both Get- and Set- cmdlets• Find a PowerCLI/PowerShell editor you like: PowerGUI,

PowerShell ISE, PowerShell Plus, NotePad++ and plenty of commercial offerings

• 30/60/90 day service desk reports: What are you repeating (KISS)? Document it, automate it.

• Share your scripts: Blog, GitHub, Twitter

Page 26: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

PowerCLI Ninja Challenge?

Page 27: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Community Resources• Twitter: @PowerCLI, @PowerCLIbot, @PowerTip,

@Powerscripting, @AlanRenouf, @JeffHicks, @vNoob• Blogs/Sites:

– http://www.virtu-al.net/ | http://www.virtu-al.net/vcheck– https://www.vmware.com/support/developer/PowerCLI/– http://professionalvmware.com/?s=powercli– http://www.vmware.com/security/hardening-guides

• Book: Learning PowerCLI– https://smile.amazon.com– https://charitywater.org– https://charitywater.org/birthdays

Page 28: Providence VMUG - PowerCLI

Providence VMUG | PowerCLI

Q&A• Twitter: @jfrappier, @vBrownBag

(hashtag: #vBrownBag)

• G+: +JonathanFrappier

• LinkedIn: /in/jonathanfrappier

• http://virtxpert.com

• http://professionalvmware.com

• Book: VMware vSphere Resource Management Essentials http://amzn.to/1fAWGzk