PowerCLI One-Liners to make your VMware environment rock out!

June 14th, 2013
by Christopher Kusek (PKGuild)

So I hadn’t touched PowerCLI in a long while (Hey, I hadn’t touched the CONSOLE OF ANYTHING near production after having been in management for so long!   So, the first thing I decided to do was, “Well, what data is important to me… and what will make my life easier!”   Below you’ll see examples of some of those very scenarios, One-Liners and collections of data points! If you haven’t worked with PowerCLI this is a good way to get started.  I’ll also explain WTF I did and why, so you have some good logic and reasoning behind why to use some of these measures!  Also if you happen to have any really cool one-liners and scripts you’ve used, feel free to toss them into the comments!

Let’s start with … Well, getting started!

Launch PowerCLI CMDLine as an elevated user (This is especially important if you have a different administrative acct than your login)

Connect-VIServer

// You can paste in all of the vCenter Names in order to execute a ‘command’ against all of them.

Example, You can simply launch Connect-VIServer, hit enter and then paste a list of vCenters to connect to.  This is especially important if you happen to be managing more than one vCenter.

Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Where {$_.ManagementTrafficEnabled} | Select Hostname, PortGroupName, IP, SubnetMask

// This will then dump the ESXi Hostnames, IPs and Subnets – For the Management Network

Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Where {$_.vMotionEnabled} | Select Hostname, PortGroupName, IP, SubnetMask

// This will then dump the ESXi Hostnames, IPs and Subnets – For the vMotion Network

Get-VMHost | Get-Cluster | Select Name, DrsEnabled, DrsMode, DrsAutomationLevel

// Dump DRS Status

Get-VMHost | Get-Cluster | Select Name, VMSwapfilePolicy

// Dump VMSwapfilePolilcy

Get-VMHost | Get-Cluster | Select Name, HAAdmissionControlEnabled

// Check status of HA Admission Control

Get-VMHost | Get-Cluster | Select Name, HAFailoverLevel, HARestartPriority, HAIsolationResponse

// Check HA Status Levels

Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Select Hostname, PortGroupName, IP, MTU

// Check for MTU Mismatches

Get-VirtualSwitch | Select VMHost, Name, MTU

// Shows what the MTU settings on the Virtual Switches are

Get-VMGuestNetworkInterface –VM VMNAME | Select VM, IP, SubnetMask, DefaultGateway, Dns

// Dumps a hosts Name, IP, Subnet, Gateway and DNS configuration

Append ‘| Export-Csv “c:\location\filename”’

// This will allow you to export the results to a CSV file  – This is called out so you’re aware of the syntax to do CSV type exports!

Get-VMHost | Get-ScsiLun | Select VMHost, ConsoleDeviceName, Vendor, MultipathPolicy

// This will dump the Multipath Policy of the storage on the systems to determine what the MP configuration is.

Get-VMHost | Get-ScsiLun | Select VMHost, ConsoleDeviceName, Vendor, MultipathPolicy | Where {$_.Vendor –eq “NETAPP”} | Select VMHost, ConsoleDeviceName, Vendor, MultipathPolicy

// This will dump the Multipath Policy of ONLY NetApp systems

Get-VMHost | Get-ScsiLun | Select VMHost, ConsoleDeviceName, Vendor, Model, LunType, MultipathPolicy | Export-CSV “C:\temp\MultipathPolicyFull.csv”

// This will dump the Multipath Policy into a CSV as it’ll be a tad bit longer with multiple attributes specified!

Get-ScsiLun –Hba [software iSCSI HBA] | Set-ScsiLun –MultipathPolicy “RoundRobin”

// You can use these parameters to change the LUNs from Fixed to RoundRobin

e.g.) Get-ScsiLun –Hba vmhba39 | Set-ScsiLun –MultipathPolicy “RoundRobin”

Get-VMhost | Get-SCSILun | Where {$_.Vendor –EQ “NETAPP”} | Select VMHost, Vendor, MultipathPolicy

// Identify the Netapp LUNs

Get-VMhost | Get-SCSILun | Where {$_.Vendor –EQ “NETAPP”} | Where {$_.MultipathPolicy -EQ "Fixed"} | Select VMHost, Vendor, MultipathPolicy

// Identify the Netapp LUNs which are “Fixed”

Get-VMhost | Get-SCSILun | Where {$_.Vendor –EQ “NETAPP”} | Set-SCSILun –MultipathPolicy “RoundRobin”

// Set the NetApp LUNs to RoundRobin

Get-VMhost | Get-SCSILun | Where {$_.Vendor –EQ “NETAPP”} | Where {$_.MultipathPolicy -EQ "Fixed"} | Set-SCSILun –MultipathPolicy “RoundRobin”

Get-VMHost | Sort Name | Select Name, @{N=”NTP”;E={Get-VMHostNtpServer $_}}

// This will dump NTP Configuration settings

Get-VMHost | Get-View | foreach {$_.Summary.Hardware.OtherIdentifyingInfo[3].IdentifierValue}

// This will dump the Dell Service Tags

Get-VMHost | Get-View | Select Name, @{N=”Service Tag”;E={$_.Summary.Hardware.OtherIdentifyingInfo[3].IdentifierValue}}

// This will dump the Host name and the Dell Service Tag

Get-VMHost | Sort Name | Get-View | Select Name, @{N=”Tag 3”;E={$_.Summary.Hardware.OtherIdentifyingInfo[3].IdentifierValue}}, @{N=”Tag 2”;E={$_.Summary.Hardware.OtherIdentifyingInfo[3].IdentifierValue}}, @{N=”Tag 1”;E={$_.Summary.Hardware.OtherIdentifyingInfo[3].IdentifierValue}}

// This will dump the Host name and the Dell Service Tag values across all 3 identifiers

Get-View -ViewType HostSystem | Sort Name | Select Name,@{N="BIOS version";E={$_.Hardware.BiosInfo.BiosVersion}}, @{N="BIOS date";E={$_.Hardware.BiosInfo.releaseDate}}

// This will dump the hosts BIOS version and date(s)

get-vmhost | Get-VMHostAdvancedConfiguration -Name Syslog.global.logHost

// Dump the current SYSLOG Configuration

You may notice that a lot of the Scripts identified in here are very selfishly scripts I’ve personally used… and I’ll tell you… that’s not all that bad ;)   I figure as time goes on, I’ll find other various switches and flags which are important and others ought to check out!  I’m constantly building and adding to this list as there are various scripts I’ll be running on a daily, weekly and monthly basis.   As I start to identify which items fall into the lists I’ll share my experiences with ya’ll here! Enjoy!

Tags: , , , , ,
Posted in PowerCLI, virt, Virtualization, vmware, vSphere | Comments (708)

  • http://chloebag.bertafv.com/ pacdffgsvdrhri

    ???????????????? ?????????????????? [url=http://pumajapan.legbadigital.com/]??? ??????[/url] ????????????? ?????????????????????http://vip.china-ef.com/web/targuo0324/???????????????????????????????? [url=http://bagcheap.mixitlimited.com/annasui/]???? ??[/url] ????3,000??????????????? ?????????????????????? [url=http://accessories.dennisbake.com/chromehearts/] ?????? ?????[/url] 11.05???????????? ??????????? [url=http://bagcheap.mixitlimited.com/annasui/]???? ?? ??[/url] ???????????????????????? ????????????????????????

  • http://www.agriturismovillasangio.it/upload/userfiles/image/jp/li/top/gaga/ pacdffgsvdrwpd

    ?????????????????????????????·??????????IWC?????????? ?????????????? [url=http://gagastore.himegimi.jp/]?????[/url] ?????????????????????? “????????????????????? [url=http://gagashow.theisraeltest.com/]?????[/url] ?????????????????????1???????????? ???????????? [url=http://gagastore.bookbinder.jp]??????? ?????[/url] ??????????????????? ??????????????????????? [url=http://sericol.hu/img/Image/e/r/shop/gaga/]gaga ?? ???[/url] ???????15??????????????????? 3??????????????????

  • http://jewelrybrand.mixitltd.net/bvlgari/ sdgfggcwq

    xunjie[url=http://www.xunjie.com/]xunjie[/url]
    ???????????? ???????????????? [url=http://celineshop.optimalrc.jp/]???? ?? ???[/url] ????????????? ????????????IBISWorld?????????? [url=http://lamystore.bertafv.com/]??? ???? ??[/url] ????????????????? ???????????????2?????????????????? [url=http://victoriasmall.amigasa.jp/]??????????????[/url] ???????????????????????? ???????????????? [url=http://montblancpen.cqmxkj.com/]????? ????? ??[/url] ?????????????????? ????????????

  • http://reebokclassic.cioleadershipawards.com/ pacdffgsvdrjas

    ????????????????????????????????? ???????—?????Senmai????????????????????? [url=http://www.dhdesigned.com/shop/gaga/]gaga ?? ?????[/url] ELLE2008???????????? ??…?????????? [url=http://www.dhdesigned.com/shop/gaga/]gaga milano ??[/url] ??????????? ???????????????????????????? [url=http://gagamilano.billyswish.org/]????? ?? ???[/url] ???????????????? ?????????? [url=http://pumashop.balatonklaszter.com/]??? ????[/url] ?????????????????????????????? ???????????????????????

  • http://tophandbag.drtiagreenberg.com/annasui/ lgfgggpjx

    xunjie[url=http://www.xunjie.com/]xunjie[/url]
    ????????????????? EU?????????????? [url=http://watchstore.drtiagreenberg.com/gaga/]????? ?? ?????[/url] ??????????????????? ??????35?????????????75????????????????????????????????????????? [url=http://jewelrysale.ecobeautiful.net/goros/]???? ????? ??[/url] ??????????? ???????230?????????????????????????????? [url=http://victoriasmall.amigasa.jp/]???????????? ?????[/url] ????????????? ?????????????????????????????????????????????????????????????????? [url=http://necklaceshop.drblivingwell.com/tiffany/]?????? ????[/url] ???????????? ?????????????????

  • http://gagawatch.miyukino.jp/ pacdffgsvdrorh

    ???????????????????? ?????????????T?????????????4???????? [url=http://gagamilano.billyswish.org/]??????? ?????[/url] ??????????????????????????????????? ????????????????????????? [url=http://www.dkadesign.net/top/annasui/]???? ??? ???[/url] ????????????????????????? ????????????????????????????? [url=http://gaganew.freshgarden.jp/]????? ?? ???[/url] 2015?????3????? ??????????? [url=http://katespadebuy.mizunojapanshop.com/]??????? ??? ??[/url] ???????????? ??????????????????

  • http://n-shingo.com/seisaku/images/r/ja/list/brand/vans/ pacdffgsvdrevv

    xunjie[url=http://www.xunjie.com/]xunjie[/url]

    ????????? “????????????????????????????????????”??????????????????????????????????????????????????????????????????????????????????????????????????????????€? ????????????????????????????????????????????????????€? [url=http://topnike.iconosites.com/]nike sko børn[/url] ?????????????????????????????????????€? ???????????????????????????????????????????????????????€? [url=http://www.agriturismovillasangio.it/upload/userfiles/image/jp/li/top/victorias/]???????????? ??[/url] ????????????????????????????????????????????????????????????????????????????????????????€? ????????????????????????????????????????????????????????????????€??????????????€? [url=http://nikebest.iconosites.com/]nike sko børn[/url] ????????????????????????????????????5??????????€? ??????????????????????????????????€? [url=http://nikestyle.iconosites.com/]nike sko børn[/url] ??????Grandbuy????????????????????????????????????????€? ????€??????????????????????????€???????????????????????€?

  • http://nikediscount.iconosites.com/ pacdffgsvdrfdg

    xunjie[url=http://www.xunjie.com/]xunjie[/url]

    2010?????????????????????????????????????????????????????????????€? ???????????????????????????????????????????€? [url=http://www.ahf.de/images/ul/image/News/p/list/gaga/]????? ?? ??[/url] ???????????????????????????????????€?????????????????????????????????????????????????????????????????????????????????????€? ???16???????????????????????????????€?????????????????€? [url=http://n-shingo.com/seisaku/images/r/jp/shop/bag/]?????? ???[/url] ???????????????????????????????????????????????????????€? ?????????????????????????????????????????????????????????????€? [url=http://nikebrand.iconosites.com/]nike sko dame[/url] ???????????????????????????????€? …???Http :/ / news.61ef.cn/2011/0811/45369.shtml 2011???8???11??? – ???????????????????????????????????????????????????????€? [url=http://n-shingo.com/seisaku/images/r/ja/list/brand/vans/]??? ?????[/url] ??????????????????????????????????????????€? ???????????????????????????????€???????????€?

  • Archives