homepage
Open menu
Go one level top
  • Train and Certify
    Train and Certify

    Immediately apply the skills and techniques learned in SANS courses, ranges, and summits

    • Overview
    • Courses
      • Overview
      • Full Course List
      • By Focus Areas
        • Cloud Security
        • Cyber Defense
        • Cybersecurity and IT Essentials
        • DFIR
        • Industrial Control Systems
        • Offensive Operations
        • Management, Legal, and Audit
      • By Skill Levels
        • New to Cyber
        • Essentials
        • Advanced
        • Expert
      • Training Formats
        • OnDemand
        • In-Person
        • Live Online
      • Course Demos
    • Training Roadmaps
      • Skills Roadmap
      • Focus Area Job Roles
        • Cyber Defence Job Roles
        • Offensive Operations Job Roles
        • DFIR Job Roles
        • Cloud Job Roles
        • ICS Job Roles
        • Leadership Job Roles
      • NICE Framework
        • Security Provisionals
        • Operate and Maintain
        • Oversee and Govern
        • Protect and Defend
        • Analyze
        • Collect and Operate
        • Investigate
        • Industrial Control Systems
    • GIAC Certifications
    • Training Events & Summits
      • Events Overview
      • Event Locations
        • Asia
        • Australia & New Zealand
        • Latin America
        • Mainland Europe
        • Middle East & Africa
        • Scandinavia
        • United Kingdom & Ireland
        • United States & Canada
      • Summits
    • OnDemand
    • Get Started in Cyber
      • Overview
      • Degree and Certificate Programs
      • Scholarships
    • Cyber Ranges
  • Manage Your Team
    Manage Your Team

    Build a world-class cyber team with our workforce development programs

    • Overview
    • Why Work with SANS
    • Group Purchasing
    • Build Your Team
      • Team Development
      • Assessments
      • Private Training
      • Hire Cyber Professionals
      • By Industry
        • Health Care
        • Industrial Control Systems Security
        • Military
    • Leadership Training
  • Security Awareness
    Security Awareness

    Increase your staff’s cyber awareness, help them change their behaviors, and reduce your organizational risk

    • Overview
    • Products & Services
      • Security Awareness Training
        • EndUser Training
        • Phishing Platform
      • Specialized
        • Developer Training
        • ICS Engineer Training
        • NERC CIP Training
        • IT Administrator
      • Risk Assessments
        • Knowledge Assessment
        • Culture Assessment
        • Behavioral Risk Assessment
    • OUCH! Newsletter
    • Career Development
      • Overview
      • Training & Courses
      • Professional Credential
    • Blog
    • Partners
    • Reports & Case Studies
  • Resources
    Resources

    Enhance your skills with access to thousands of free resources, 150+ instructor-developed tools, and the latest cybersecurity news and analysis

    • Overview
    • Webcasts
    • Free Cybersecurity Events
      • Free Events Overview
      • Summits
      • Solutions Forums
      • Community Nights
    • Content
      • Newsletters
        • NewsBites
        • @RISK
        • OUCH! Newsletter
      • Blog
      • Podcasts
      • Summit Presentations
      • Posters & Cheat Sheets
    • Research
      • White Papers
      • Security Policies
    • Tools
    • Focus Areas
      • Cyber Defense
      • Cloud Security
      • Digital Forensics & Incident Response
      • Industrial Control Systems
      • Cyber Security Leadership
      • Offensive Operations
  • Get Involved
    Get Involved

    Help keep the cyber community one step ahead of threats. Join the SANS community or begin your journey of becoming a SANS Certified Instructor today.

    • Overview
    • Join the Community
    • Work Study
    • Teach for SANS
    • CISO Network
    • Partnerships
    • Sponsorship Opportunities
  • About
    About

    Learn more about how SANS empowers and educates current and future cybersecurity practitioners with knowledge and skills

    • SANS
      • Overview
      • Our Founder
      • Awards
    • Instructors
      • Our Instructors
      • Full Instructor List
    • Mission
      • Our Mission
      • Diversity
      • Scholarships
    • Contact
      • Contact Customer Service
      • Contact Sales
      • Press & Media Enquiries
    • Frequent Asked Questions
    • Customer Reviews
    • Press
    • Careers
  • Contact Sales
  • SANS Sites
    • GIAC Security Certifications
    • Internet Storm Center
    • SANS Technology Institute
    • Security Awareness Training
  • Search
  • Log In
  • Join
    • 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
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
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
Macedonia
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
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
Swaziland
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania
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
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Yugoslavia
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

  • SEC511: Continuous Monitoring and Security Operations
  • SEC540: Cloud Security and DevSecOps Automation
  • SEC565: Red Team Operations and Adversary Emulation

Tags:
  • Cloud Security
  • Security Management, Legal, and Audit

Related Content

Blog
CD_Blog_HowtoautomateinAzure_Part1_2.jpg
Cyber Defense, Cloud Security
October 11, 2022
How to Automate in Azure Using PowerShell - Part 1
In this post, we’ll cover how to automate the assessment and reporting of your cloud security configuration opportunities.
370x370_josh-johnson.jpg
Josh Johnson
read more
Blog
powershell_option_340x340.jpg
Cyber Defense, Cybersecurity and IT Essentials, Cloud Security, Penetration Testing and Red Teaming
July 17, 2022
Month of PowerShell: Merging Two Files (Understanding ForEach)
A routine task (merging two files) leads us down the path of developing a better understanding of the ForEach command in PowerShell.
370x370_Joshua-Wright.jpg
Joshua Wright
read more
Blog
SOC2-340x340.png
Security Management, Legal, and Audit
April 7, 2022
SANS SOC 2 Resources
Stay current with free resources focused on SOC 2.
MGT_Triad_370x370_Headshot.jpg
SANS Cybersecurity Leadership
read more
  • Register to Learn
  • Courses
  • Certifications
  • Degree Programs
  • Cyber Ranges
  • Job Tools
  • Security Policy Project
  • Posters & Cheat Sheets
  • White Papers
  • Focus Areas
  • Cyber Defense
  • Cloud Security
  • Cybersecurity Leadership
  • Digital Forensics
  • Industrial Control Systems
  • Offensive Operations
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
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
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
Macedonia
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
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
Swaziland
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania
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
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Yugoslavia
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.
  • © 2023 SANS™ Institute
  • Privacy Policy
  • Contact
  • Careers
  • Twitter
  • Facebook
  • Youtube
  • LinkedIn