homepage
Menu
Open menu
  • Training
    Go one level top Back

    Training

    • Courses

      Build cyber prowess with training from renowned experts

    • Hands-On Simulations

      Hands-on learning exercises keep you at the top of your cyber game

    • Certifications

      Demonstrate cybersecurity expertise with GIAC certifications

    • Ways to Train

      Multiple training options to best fit your schedule and preferred learning style

    • Training Events & Summits

      Expert-led training at locations around the world

    • Free Training Events

      Upcoming workshops, webinars and local events

    • Security Awareness

      Harden enterprise security with end-user and role-based training

    Featured: Solutions for Emerging Risks

    Discover tailored resources that translate emerging threats into actionable strategies

    Risk-Based Solutions

    Can't find what you are looking for?

    Let us help.
    Contact us
  • Learning Paths
    Go one level top Back

    Learning Paths

    • By Focus Area

      Chart your path to job-specific training courses

    • By NICE Framework

      Navigate cybersecurity training through NICE framework roles

    • DoDD 8140 Work Roles

      US DoD 8140 Directive Frameworks

    • By European Skills Framework

      Align your enterprise cyber skills with ECSF profiles

    • By Skills Roadmap

      Find the right training path based on critical skills

    • New to Cyber

      Give your cybersecurity career the right foundation for success

    • Leadership

      Training designed to help security leaders reduce organizational risk

    • Degree and Certificate Programs

      Gain the skills, certifications, and confidence to launch or advance your cybersecurity career.

    Featured

    New to Cyber resources

    Start your career
  • Community Resources
    Go one level top Back

    Community Resources

    Watch & Listen

    • Webinars
    • Live Streams
    • Podcasts

    Read

    • Blog
    • Newsletters
    • White Papers
    • Internet Storm Center

    Download

    • Open Source Tools
    • Posters & Cheat Sheets
    • Policy Templates
    • Summit Presentations
    • SANS Community Benefits

      Connect, learn, and share with other cybersecurity professionals

    • CISO Network

      Engage, challenge, and network with fellow CISOs in this exclusive community of security leaders

  • For Organizations
    Go one level top Back

    For Organizations

    Team Development

    • Why Partner with SANS
    • Group Purchasing
    • Skills & Talent Assessments
    • Private & Custom Training

    Leadership Development

    • Leadership Courses & Accreditation
    • Executive Cybersecurity Exercises
    • CISO Network

    Security Awareness

    • End-User Training
    • Phishing Simulation
    • Specialized Role-Based Training
    • Risk Assessments
    • Public Sector Partnerships

      Explore industry-specific programming and customized training solutions

    • Sponsorship Opportunities

      Sponsor a SANS event or research paper

    Interested in developing a training plan to fit your organization’s needs?

    We're here to help.
    Contact us
  • Talk with an expert
  • Log In
  • Join - it's free
  • Account
    • Account Dashboard
    • Log Out
  1. Home >
  2. Blog >
  3. Using the VMWare PowerCLI modules to Measure VMWare Compliance
370x370_Clay-Risenhoover.jpg
Clay Risenhoover

Using the VMWare PowerCLI modules to Measure VMWare Compliance

This is Part 2 of a 3-part Series on Using PowerShell for Continuous Audit & Compliance Automation in Enterprise & Cloud

February 4, 2021

This is the second of a three-part series on using PowerShell for audit and compliance measurements. These blog posts supplement the material presented in the free webcast series "PowerShell for Audit, Compliance, and Security Automation and Visualization".

  • Read Part 1 of the Blog here
  • Read Part 3 of the Blog here

If you are using VMWare products like vSphere Hypervisor (ESXi) and vCenter server in your on-premise environment, you may need to test them for compliance with enterprise policies or security benchmarks. Sticking with the theme of this series, in this post I will show you how to use the PowerCLI suite of PowerShell modules to take measurements of your VMWare systems.

Installing the PowerCLI Modules

You can install the PowerCLI software as a package from PSGallery using this command:

Install-Module -Name VMware.PowerCLI

Blog2-1.png

PowerCLI is really a suite of script-based modules which provide the ability to query and manage your VMWare infrastructure. I can view the modules included with the installed module using the Get-Module cmdlet:

Get-Module -Name VMWare*

Blog2-2.png

As an auditor and compliance consultant, I generally use only the Get-* cmdlets included with most modules. PowerCLI includes a LOT of Get- cmdlets. My version of PowerCLI includes 307 different Get cmdlets.

Blog2-3.png

Common VMWare Configuration

While most of your compliance testing will focus on your hypervisor (ESXi) host settings, most enterprises don't manage the ESXi hosts directly. Instead, they setup a vCenter server, often as a VM running in the virtualized environment. You may have heard your engineers refer to the vCenter Server Appliance (VCSA) being used to manage the hosts. Your technical staff might use the web interface on the vCenter server to control what happens on the hosts. You will use PowerCLI to run your tests against the vCenter server and the hosts it manages. A common architecture might like this:

Blog2-4.png

Compliance Testing VMWare

With the large number of available cmdlets, the biggest problem you are likely to face with VMWare compliance measurements is finding the right combination of commands to use to gather the information you need. I'll work through several examples to demonstrate how you can go about your data gathering. We'll start with authenticating to the vCenter server.

Store Credentials Securely

For most of your VMWare compliance testing, you will connect and authenticate to the vCenter server, and then use that connection to query settings on the vCenter server and the hosts it manages. If you are working interactively at the console, you can use the Get-Credential cmdlet to get a PSCredential object, which contains the username as a string, and the password as a SecureString object (which encrypts the password in memory). If you are building scripts to run automatically, especially under PowerShell Core on non-Windows systems, you'll need a secure way of saving credentials for access in the script. If you work in a DevOps environment where you have a password vault (like Hashicorp Vault), you can save credentials there. If not, you can save your password in a symmetrically encrypted file.

Start by getting your credentials in memory using Get-Credential:

$cred= Get-Credential

BLog2-5.png

Next, you can create a symmetric key file to be used to encrypt your password. Use the .NET cryptographic random number generator to build a key of an appropriate size - 256 bits in this example. Be sure that you set the permissions on the key file so that only authorized users can read it, since it will be used to decrypt your password!

#Create a new key byte array and fill it
$Key = New-Object Byte[] 16
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
#Send to the key file</p>
$Key | Out-File .\keyFile

Then, you can save the password to a file, encrypted with the key.

$cred.Password | ConvertFrom-SecureString -Key $Key | Out-File .\esxiPassword

Blog2-6.png

Now, whenever you need credentials for the vCenter server, you can build a PSCredential object using a username and your saved password.

$key = Get-Content .\keyFile
$encryptedPwd = Get-Content .\esxiPassword
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList 'auditor@sec557.local',`
  ($encryptedPwd | ConvertTo-SecureString -Key $key)
Connect-VIServer -Server 10.50.7.33 -Credential $cred

Blog2-7.png

Note that the "auditor@sec557.local" user in these examples has been granted a custom role called "AuditRole" on the vCenter server. AuditRole is a clone of the built-in "Read-only" role with the "Global settings" permission added for the vCenter server and all its child objects. vCenter allows for very granular control over the access provided to users.

Blog2-8.png

Verify ESXi Version

Now that we've connected to the vCenter server, let's start our data gathering with a very common management requirement: ensure that all ESXi hosts are running a current, supported, version of the software. Today, versions 6.5, 6.7 and 7.0 are all supported. 6.5 and 6.7 were released and will lose support simultaneously. 6.5 supports some older CPUs than 6.7, which means that if you see 6.5 in the datacenter, you may want to follow up on the hardware in use to see if it can run the newer versions of ESXi.

Let's query the vCenter server to get the version information for all the ESXi hypervisors it manages:

Get-VMHost | Select-Object Name, Version, Build

Blog2-9.png

Next, you could research the version numbers using this VMWare knowledge base article, which lists every ESXi version back to ESXi version 4.0, released in 2009.

You could do a similar check for the vCenter server by querying it directly. The vCenter server(s) you are currently connected to is available through the DefaultVIServers global variable.

$Global:DefaultVIServers | select Name, Version, Build

Blog2-10.png

The VMWare knowledge base article for vCenter versions is your resource for checking whether your version is current.

Other Patching Compliance Checks

Patch data can be retrieved with the ESXCLI cmdlets, which emulate the results you would receive if were to run commands in the command line interface (CLI) at the host's console. To check patching on an ESXi host, you need to get a list of the "VIBs" (vSphere Installation Bundles) installed on the machine.

(Get-VMHost -Name 10.50.7.31 | Get-EsxCli).software.vib.list()

We frequently take two measurements related to patching: the "patch age" of a system is the number of days since the last patch was installed, and "patch velocity" measures the number of patches installed per date. Patch velocity can be obtained with a query like this:

(Get-VMHost -Name 10.50.7.31 | Get-EsxCli).software.vib.list() | 
  Group-Object InstallDate

Blog2-11.png

This host has only been patched twice, In November 2019, 82 packages were installed, probably when the host was deployed. Then in December of 2020 (maybe when the administrators heard an auditor was coming!) another 41 packages were installed. If the enterprise's policies call for regular patching, this host is probably out of compliance.

To calculate patch age, we will get the InstallDate of the most recently install patch and measure the number of days between then and now. We can use a TimeSpan PowerShell object to see how many days it has been since the host was last patched.

$lastPatchDate = ((Get-VMHost -Name 10.50.7.31 | Get-EsxCli).software.vib.list() | 
  Sort-Object InstallDate -Descending | Select-Object -First 1).InstallDate</
$patchAge = (New-TimeSpan -Start $lastPatchDate -End (Get-Date)).Days</
$patchAge<

Blog2-12.png

This host was last patched 34 days ago.

Verify Host Service Settings

Many security policies and benchmarks require ESXi servers to be configured to use NTP for time synchronization. To check this, you'll need to look at two things:

  • Is the host set to use the correct NTP server?
  • Is the NTP service enabled and running?

Let's start with checking the service status on the two hosts in the lab.

Get-VMHost | Get-VMHostService | 
  Where-Object {$_.key -eq "ntpd"} |
  Select-Object VMHost, Label, Key, Policy, Running, Required

Blog2-13.png

Notice that both hosts have the NTP service disabled and not running! It really doesn't matter what NTP server the hosts are set to use, but let's check the settings anyway. The NTP server setting can be queried using a cmdlet built for the task. I usually combine the service configuration and server settings into a single big query. I'm using PowerShell's "calculated properties" here to organize the results:

Get-VMHost | Sort Name | Select Name, `
    @{Name="NTPServer";Expression={$_ | Get-VMHostNtpServer}}, `
    @{N="ServiceRunning";E={(Get-VmHostService -VMHost $_ |
        Where-Object {$_.key-eq "ntpd"} ).Running}}, `
    @{N="ServiceRequired";E={(Get-VmHostService -VMHost $_ |
        Where-Object {$_.key-eq "ntpd"} ).Required}}

Blog2-14.png

Notice that the second server has no NTP server configured at all.

DNS Server Settings

When there is not a cmdlet to directly query a setting, you can often find what you need in the ExtensionData property returned by the Get-VMHost cmdlet. Here's a quick example of querying the DNS server settings for my lab servers.

(Get-VMHost).ExtensionData.Config.Network.DNSConfig

Blog2-15.png

Honorable Mentions

I'd be remiss if I didn't mention a couple of other tools which have been helpful in auditing and analyzing VMWare.

Robware RVTools

The first is Robware RVTools. It's Windows .NET application with a heavily tabbed interface. Simply point it at your vCenter server, login, and view all sorts of inventory information from your infrastructure.

Blog2-16.png

Blog2-17.png

One of my favorite features of RVTools is the vHealth tab, which can show you common compliance issues without having to run any queries.

Blog2-18.png

The other feature I love is the ability to export the data from RVTools to a tabbed Excel spreadsheet:

Blog2-19.png

AsBuiltReport PowerShell Module

Finally, I leave you with the ASBuiltReport PowerShell modules. This ever-growing set of tools can be run against several different infrastructure technologies, including VMWare. After installing the modules, you can build a nice HTML or Word document which details your infrastructure.

New-AsBuiltReport -Report VMware.vSphere -Target 10.50.7.33 -Format HTML -OutputPath 'C:\Users\auditor\Documents\' -Timestamp -Credential $cred

The resulting HTML report is very nicely formatted and helpful for understanding the configuration and inventory of your datacenter environment. Just a couple of samples from my home lab are included below.

Blog2-20.png

Blog2-21.png

Share:
TwitterLinkedInFacebook
Copy url Url was copied to clipboard
Subscribe to SANS Newsletters
Receive curated news, vulnerabilities, & security awareness tips
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Cote D'ivoire
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Eswatini
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
North Macedonia
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Saudi Arabia
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania, United Republic Of
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City State
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Zambia
Zimbabwe

By providing this information, you agree to the processing of your personal data by SANS as described in our Privacy Policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Recommended Training

  • SEC599: Defeating Advanced Adversaries - Purple Team Tactics & Kill Chain Defenses™
  • SEC401J: Security Essentials - Network, Endpoint, and Cloud™ (Japanese)
  • SEC573: Automating Information Security with Python™

Tags:
  • Cloud Security
  • Cybersecurity Leadership

Related Content

Blog
SEC540_Updated_340x340.png
Cloud Security
December 29, 2023
What is the SANS Cloud Flight Simulator?
Get ready for takeoff into the NEW SEC540!
Eric_Johnson_370x370.png
Eric Johnson
read more
Blog
Rethinking_Compliance_340x340.png
Cloud Security
October 10, 2023
Rethinking Cybersecurity Compliance: The Underutilized Power of CSP Native Security Services
Live off the land for cloud compliance
370x370_AJ-Yawn_CloudSEcNext.jpg
AJ Yawn
read more
Blog
SSA_-_Blog_-_Building_a_Cybersecurity_and_Privacy_Learning_Program_-_340x340.jpg
Cybersecurity Leadership, Security Awareness
September 12, 2023
NIST’s SP800-50r1 – Building a Cybersecurity and Privacy Learning Program
Overall, this document is really about defining and meeting training requirements.
370x370_Lance-Spitzner.jpg
Lance Spitzner
read more
  • Company
  • Mission
  • Instructors
  • About
  • FAQ
  • Press
  • Contact Us
  • Careers
  • Policies
  • Training Programs
  • Work Study
  • Academies & Scholarships
  • Public Sector Partnerships
  • Law Enforcement
  • SkillsFuture Singapore
  • Degree Programs
  • Get Involved
  • Join the Community
  • Become an Instructor
  • Become a Sponsor
  • Speak at a Summit
  • Join the CISO Network
  • Award Programs
  • Partner Portal
Subscribe to SANS Newsletters
Receive curated news, vulnerabilities, & security awareness tips
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Cote D'ivoire
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Eswatini
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
North Macedonia
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Saudi Arabia
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania, United Republic Of
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City State
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Zambia
Zimbabwe

By providing this information, you agree to the processing of your personal data by SANS as described in our Privacy Policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
  • Privacy Policy
  • Terms and Conditions
  • Do Not Sell/Share My Personal Information
  • Contact
  • Careers
© 2025 The Escal Institute of Advanced Technologies, Inc. d/b/a SANS Institute. Our Terms and Conditions detail our trademark and copyright rights. Any unauthorized use is expressly prohibited.
  • Twitter
  • Facebook
  • Youtube
  • LinkedIn