Sheridan Wendt
  • Home
  • Technology
  • Business
  • Music
  • Adventures
  • Resume
  • Contact

Technology

Scanning Storage in vCenter with Powershell

3/31/2018

Comments

 
Ever wanted to rescan storage on all of the ESXi hosts in your vCenter environment at once?This article shows how to write a PowerShell script that will rescan a list of ESXi hosts in your environment for new storage, either VFMS, NTFS, or both.
Click below to view the full script on github
VMWare Rescan Storage.ps1
First up, you'll need to download VMWare's PowerShell module called PowerCLI (Command Line Interface). If you're using this locally, it can be downloaded from VMWare, from the PowerShell Gallery, or right inside of PowerShell. If you're using PowerShell in Azure, it can be deployed to an Azure Automation. At the time of writing, the commands below are all that is needed to download and install the module directly while inside of PowerShell.

To download the module: 
PS> Save-Module -Name VMware.PowerCLI -Path <path>
To install the module
PS> Install-Module -Name VMware.PowerCLI
Once the module is installed, it's time to get busy! First up, we'll define some variables. You'll need to know the name of the vCenter server to connect and the appropriate cluster. If there are multiple clusters in your environment, they can be placed in an array and then used with a foreach statement. In this script, there is only one vCenter server and one cluster.
# Set variables
$Cluster = "ClusterName"
$vCenter = "vcenter.domain.local"
After defining the variables, we'll connect to the vCenter server with this command:
Connect-VIServer $vCenter
Now that we're connected, it's time to scan. There are two types of scans:
  1. Scan for HBAs (Host Bus Adapters). HBAs are considered new storage devices. These would be storage devices that are not already added to vCenter or the hosts, not necessarily newly connected devices. 
  2. Scan for VMFS (Virtual Machine File System) volumes. These are the volumes that are created within Datastores. Its the file system used within Datastores that contain .vmdks, .vmx, and other VM related files.
Decision time! From here you'll want to decide whether you want to scan for HBAs, VMFS volumes, or both. Remember, your choice will have an impact on how long the scan takes to complete. It will take much longer if you choose both, but sometimes this is the best approach if you have new storage devices (HBAs) that already contain VMFS volumes on them. The only difference between the two commands is the switch at the end. The commands are below:
  • Rescan HBAs:
Get-Cluster -Name $Cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba
  • Rescan VMFS volumes:
​Get-Cluster -Name $Cluster | Get-VMHost | Get-VMHostStorage -RescanVmfs
  • Rescan both:
  1. Get-Cluster -Name $Cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs
​That's all there is to it! Stay tuned for some more VMWare goodies.
Comments

    Repositories

    PowerShell
    SQL

    Author

    Sheridan's interests are in technology, business, music, and adventures

    View my profile on LinkedIn

    RSS Feed

    Categories

    All
    Alerts
    Azure
    Business Intelligence
    Data Visualization
    Notifications
    Photo Frame
    PowerShell
    Raspberry Pi
    Scripting
    SMS
    SQL
    Technology
    Virtualization
    VMWare

    Business

    Archives

    June 2019
    May 2019
    September 2018
    May 2018
    April 2018
    March 2018
    February 2018
    December 2017
    September 2017
    July 2003

Powered by Create your own unique website with customizable templates.
  • Home
  • Technology
  • Business
  • Music
  • Adventures
  • Resume
  • Contact