A repository of useful PowerCLI scripts for your daily SysAdmin duties
Note! This repo is currrently W.I.P. - code will be added time to time
This is a repository containing useful scripts to perform various tasks on your VMware infrastructure.
The scripts in this repo were tested on an environment running:
Client-Side
- PowerShell version 5.1
- PowerCLI 13.0
Server-Side
- VMware vCenter Server 7.0.3
You can check your PowerShell version by running $PSVersionTable
.
If you don't have the PowerCLI modules installed, you can do so by running Install-Module -Name VMware.PowerCLI
on an elevated PowerShell (documentation).
After the installation, i suggest to:
-
Suppress the CEIP message by running
Set-PowerCLIConfiguration -Scope AllUsers -ParticipateInCeip $false
-
If you are dealing with self-signed certificates, add an exception to ignore them by default with
Set-PowerCLIConfiguration -Scope AllUsers -InvalidCertificateAction Ignore
There are several ways to retrieve the scripts. For example, you can either:
-
Download the whole branch as a .ZIP archive by clicking Code > Download ZIP (or here)
-
Download a single script directly from the PowerShell. For example, to download the script Powerstate-Report.ps1 you can use the following snippet:
Invoke-WebRequest -URI https://raw.githubusercontent.com/EarlyOwl/PowerCLI-SysAdmin-Repo/main/scripts/Powerstate-Report.ps1 -Outfile Powerstate-Report.ps1
REMEMBER: you should adjust the connection parameters in the scripts to fit your environment!
# Connect to vCenter server
Connect-VIServer -Server vcenter.domain.com -User yourusernamehere -Password yourpasswordhere
Each script comes with its own embedded documentation. For example, to check the docs for the script Powerstate-Report.ps1 you can do so by running:
Get-Help .\Powerstate-Report.ps1 -full
Anyways, a brief description of every script can be found in the next chapter.
- Powerstate-Report.ps1
- Datastores-Report.ps1
- Get-Portgroups.ps1
- Massive-Shutdown.ps1
- Vmwaretools-Report.ps1
This script retrieves the power state, uptime and last boot time of all the VMs. It then outputs everything on a nicely formatted HTML table.
This script retrieves informations about the datastores in the datacenter, like name, available space, free space percentage, etc. It then outputs everything on a nicely formatted HTML table.
This script retrieves the list of the portgroups for each vDS. It then outputs everything on a nicely formatted HTML table.
This script shuts down every VM it finds in the vCenter, except the vCenter itself (the hostname of the vCenter MUST be specified inside the script). As this script doesn't produce any output file, there isn't a sample output tab below.
This script enumerates all the VMs and verifies whether or not they have Vmware Tools installed (and if so, it checks the current version). It then outputs everything on a nicely formatted HTML table.
Yes and yes.
I'm eager to learn, open an issue or a pull request to suggest an improvement / fix.