VMware PowerCLI script: collect vSphere data for LICENSEWARE
Run the Licenseware PowerCLI script to collect VMware infrastructure data, then upload the output to Infrastructure Mapper (IFMP).
PowerCLI is VMware’s vSphere command-line and scripting tool, built on Windows PowerShell. The script uses it to extract an overview of the virtual infrastructure. To use this collection method, you will need a Windows machine with network access to your vCenter Server instance(s) and to the VMware infrastructure. Additionally, the Windows machine needs to have the PowerCLI software installed.
To run a script in PowerCLI, follow these steps:
0. Pre-requisites
- Network connectivity between vCenter Server and the workstation with PowerCLI installation.
- The Administrator user password is known for all vCenter Servers.
1. Install PowerCLI
First, please make sure that you have the latest version of PowerCLI installed on your machine. You can install it by running this command in an elevated PowerShell window:
Install-Module -Name VMware.PowerCLI -Scope CurrentUserIf prompted to trust the repository, type ‘Y’ and hit Enter.
2. Launch PowerCLI
Open a new PowerShell window and launch PowerCLI by typing the following command:
Import-Module VMware.PowerCLI3. Connect to your vCenter or ESXi host
To connect to your vCenter Server or ESXi host, run the following command with your credentials:
Connect-VIServer -Server <server-address> -User <username> -Password <password>Replace
4. Run the script
To run the script in PowerCLI, change the directory (cd) to a directory where you have write permission, and use the following command to execute the script:
.\path\to\your\VCenter_inventory.ps1You can find our PowerCLI script here.
Replace path\to\your\VCenter_inventory.ps1 with the actual path and name of the script file. The script will execute in the PowerCLI environment, and you’ll see the results in the PowerShell window.
The following output files will be created under the current directory:
<VCenter Server Name>-HW-Inventory-Information.csvWhere
Troubleshooting
Section titled “Troubleshooting”- Policy restrictions: since the script you create is not digitally signed, you might encounter an issue when running it. If you receive any policy issues error message, please Copy and Paste the .ps1 code directly into the Windows Powershell console. This way, you should be able to execute the script. However, keep in mind that you will be limited by your current user privileges.
Alternatively, you may need to change the execution policy on your machine. You can do this by running the following command in an elevated PowerShell window:
Set-ExecutionPolicy RemoteSignedType ‘Y’ and hit Enter if prompted to confirm the change. This will allow you to run locally created scripts while still requiring remote scripts to be signed by a trusted publisher.
- PowerCLI login: please make sure you use the correct login credentials when connecting through PowerCLI. You can use simple commands to see if you have enough privileges:
$Global:DefaultVIServers- Insufficient privileges: please check if you have enough privileges to write by creating a test folder:
Mkdir Test