Category: vSphere Scripts

getVMwareLicenses.ps1


## getVMwareLicenses.ps1
## Script function: Get VMware licensing information from multiple vCenter Servers
## Author: Erik Hinderer @VMW ehinderer@vmware.com
## Version 1.6
## Set multi-server vCenter Mode
# Adds the base cmdlets
Add-PSSnapin VMware.VimAutomation.Core
$config = Get-PowerCLIConfiguration 
if($config.DefaultVIServerMode -eq "Single"){
    Set-PowerCLIConfiguration -DefaultVIServerMode Multiple
}
## Connect to vCenter Servers
$vclist = @(Read-Host "Enter each vCenter server separated with a comma").split(',') | % {$_.trim()}
"Please enter your vCenter credentials"
$creds = get-credential "root"
connect-viserver -server $vclist -credential $creds -WarningAction 0
$vSphereLicInfo = @()
$ServiceInstance = Get-View ServiceInstance
Foreach ($LicenseMan in Get-View ($ServiceInstance | Select -First 1).Content.LicenseManager) {
    Foreach ($License in ($LicenseMan | Select -ExpandProperty Licenses)) {
        $Details = "" |Select VC, Name, Key, Total, Used, ExpirationDate , Information
        $Details.VC = ([Uri]$LicenseMan.Client.ServiceUrl).Host
        $Details.Name= $License.Name
        $Details.Key= $License.LicenseKey
        $Details.Total= $License.Total
        $Details.Used= $License.Used
        $Details.Information= $License.Labels | Select -expand Value
        $Details.ExpirationDate = $License.Properties | Where { $_.key -eq "expirationDate" } | Select -ExpandProperty Value
        $vSphereLicInfo += $Details
    }
}
$vSphereLicInfo | Select-Object VC,Name,Key,Total,Used,ExpirationDate,Information | Export-Csv C:\VMwareLicenses_$vclist.csv -notype
disconnect-viserver * -confirm:$false

setLinuxVMNetworking.ps1


#Change the networking properties of a Linux guest VM - setLinuxVMNetworking.ps1
#Erik Hinderer
#ehinderer@vmware.com
#Version 0.1

###Run the script and enter the vCenter and Linux VM network information as prompted###

$vclist = @(Read-Host "Please enter the FQDN or IP address of vCenter Server")
"Please enter your vCenter credentials"
$creds = get-credential "root"
$linuxVMname = @(Read-Host "Please enter the VM name of the Linux guest OS you wish to change")
$IP = @(Read-Host "Please enter the IP address you wish to set the Linux guest to")
$NETMASK = @(Read-Host "Please enter the NETMASK address you wish to set the Linux guest to")
$GATEWAY = @(Read-Host "Please enter the GATEWAY address you wish to set the Linux guest to")
connect-viserver -server $vclist -credential $creds -WarningAction 0

Get-VMGuestNetworkInterface $linuxVMname -GuestCredential (Get-Credential) | Where-Object { $_.ip -ne $null} | Set-vmguestnetworkinterface -ip $IP -netmask $NETMASK -gateway $GATEWAY -GuestCredential (Get-Credential)

backupvds.ps1


#VMware VDS Backup PowerShell Script - backupvds.ps1
#Erik Hinderer
#ehinderer@vmware.com
#Version 0.2

param
(
[String] $ConfigurationFile = $(throw “Please specify the configuration file for the Content move.`r`nExample:`r`n`tGet-MachineLookup.ps1 -ConfigurationFile `”E:\Directory\ChangeThisPath.xml`””)
)

Import-Module VMware.VimAutomation.Vds

switch (Test-Path $ConfigurationFile)
{
True {Write-Host “Using $ConfigurationFile For Script Variables”
$Properties = [xml](Get-Content $ConfigurationFile)
}
False {Write-Host “$ConfigurationFile Not Found For Script Variables – Quitting”
Exit
}
}

$vCenters=$Properties.Configuration.Properties.vCenterList
$vCenterList = $vCenters.Split(“;”)
$BackupFolder = $Properties.Configuration.Properties.BackupFolder

foreach($vCenter in $vCenterList)
{
$date=get-date -uformat %d
$BackupPath=”$($BackupFolder)\$($Date)\$($vCenter)”

New-item -Type Directory -Path $BackupPath -force

connect-viserver $vcenter -force
$switches=get-vdswitch
foreach ($switch in $switches)
{
#
# Backup each vNetwork Distributed Switch not including the port groups
export-vdswitch $switch -Withoutportgroups -Description “Backup of $switch without port groups” -Destination “$($BackupPath)\$switch.without_portgroups.zip” -force
#
# Backup each vNetwork Distributed Switch including the port groups
export-vdswitch $switch -Description “Backup of $switch with port groups” -Destination “$($BackupPath)\$switch.with_portgroups.zip” -force
#
# Backup each port group individually
get-vdswitch $switch | Get-VDPortgroup | foreach { export-vdportgroup -vdportgroup $_ -Description “Backup of port group $($_.name)” -destination “$($BackupPath)\$($_.name).portgroup.zip” -force}
}
}