Simplifying VMware Virtual Machine Provisioning with PowerShell

Efficiently provisioning new virtual machines in VMware can greatly enhance productivity and streamline IT operations. This PowerShell script automates the process of creating virtual machines, allowing administrators to quickly set up new environments without manual interference.
This script will:
1. Connect to the VMware vSphere server.
2. Define parameters for the new virtual machine.
3. Create the virtual machine with specified configurations.
By using this script, IT administrators can ensure consistency and speed in virtual machine provisioning, ultimately improving operational efficiency.

# Load VMware PowerCLI module
if (-Not (Get-Module -ListAvailable -Name VMware.PowerCLI)) {
    Install-Module -Name VMware.PowerCLI -Scope CurrentUser -AllowClobber
}
# Connect to VMware vSphere
$vcServer = "your-vcenter-server"  # Replace with your vCenter server address
$credential = Get-Credential
Connect-VIServer -Server $vcServer -Credential $credential
# Define parameters for the new VM
$vmName = "NewVM"  # Name of the new virtual machine
$vmTemplate = "WindowsTemplate"  # Replace with your template name
$datastore = "Datastore1"  # Specify the datastore to use
$network = "VM Network"  # Specify the network to connect to
$vmResourcePool = "Resources"  # Specify the resource pool
# Create the new VM from template
New-VM -Name $vmName -Template $vmTemplate -Datastore $datastore -NetworkName $network -ResourcePool $vmResourcePool -Confirm:$false
Write-Host "Virtual machine '$vmName' has been provisioned successfully."
# Disconnect from VMware vSphere
Disconnect-VIServer -Server $vcServer -Confirm:$false
Write-Host "VM provisioning process completed."