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 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 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:
Get-Cluster -Name $Cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba
Get-Cluster -Name $Cluster | Get-VMHost | Get-VMHostStorage -RescanVmfs
That's all there is to it! Stay tuned for some more VMWare goodies.
|
RepositoriesAuthorSheridan's interests are in technology, business, music, and adventures Categories
All
Archives
June 2019
|