Category Archives: vSphere

vSphere Posts

PowerCLI Validation Quick Scripts

I recently built a vSphere platform, and following completion of the build I was required to perform testing, and also validate that the build matched the design documents, rather than screen print a load of images for each host etc, I used PowerCLI to get the settings for me so I could compare them with the design document. I am just going to put a list of the commands, there’s nothing overly complicated or even elegant here, but they might come in handy for someone.

Get Hosts Build Numbers

Get-VMHost | Select Name,Version,Build sort-object name

Check hosts are joined to a domain

Get-VMHost | Get-VMHostAuthentication | Select-Object VMhost,DOmain,DomainMembershipStatus | Sort-Object VMhost

 Get DRS Status

Get-Cluster  Select-Object Name,DrsEnabled,DrsMode,DrsAutomationLevel

 Get Lockdown mode status

Get-View  -ViewType  HostSystem  Select
Name, @{N=“Version”;E={$_.Summary.Config.Product.Name}}, @{N=“State”;E={$_.Runtime.ConnectionState}}, @{N=“LockedMode”;E={$_.Config.AdminDisabled}} |
Where { $_.Version -match “i”} Sort-Object  Name

 Check if ESXi Shell is running on hosts

Get-VMHost Get-VMHostService  Where { $_.Key -eq “TSM”} | Select-Object VMhost,Key,Label,RUnningSort-Object VMHost

 Check is SSH Service is running on hosts

Get-Cluster | Get-VMHost | Get-VMHostService Where { $_.Key -eq “TSM-SSH”} Select-Object VMhost,Label,RunningSort-Object VMHost

 Enable SSH on all hosts

Get-Cluster | Get-VMHost | Foreach { Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq “TSM-SSH”} ) 

}

 Get Cluster HA Status

Get-Cluster | Select-Object Name,HAEnabled,HAAdmissionControlEnabled,HAFailoverLevel,HAIsolationResponse,HARestartPriority

 Get HA Reservations

Get-Cluster clustername | Select-Object Name,@{N=“CpuFailoverResourcesPercentage”;E={$_.ExtensionData.Configuration.DasConfig.AdmissionControlPolicy.CpuFailoverResourcesPercent}},@{N=“MemoryFailoverResourcesPercentage”;E={$_.ExtensionData.Configuration.DasConfig.AdmissionControlPolicy.MemoryFailoverResourcesPercent}} |
Sort-Object Name | ft -AutoSize

 Get Host Multipath policy

Get-VMHost | Get-ScsiLun | Select-Object VMhost,CanonicalName,LunType,MultipathPolicy | Sort-Object VMhost

 Get Storage IO Control Status

Get-Datastore | Select Name,StorageIOControlEnabled

 Get Scratch partition settings

Get-VMhost | Get-AdvancedSetting -Name “ScratchConfig.ConfiguredScratchLocation” | Select-Object Entity,Name,Value | Sort-Object Entity

 Check Syslog allowed through firewall

Get-VMHost | Get-VMHostFirewallException | where {$_.Name.StartsWith(‘syslog’)}

 Check vLAN Port taggings on Portgroups

$esxihosts = Get-VMHost

foreach($esxihost in $esxihosts){

Get-VirtualPortGroup -VMHost $esxihost | select $esxihost.Name,Name, VirtualSwitch, VLanId

}

 Check DNS Resolution for all hosts (from list of hosts in text file)

$hosts = Get-Content C:\SDCHosts.txt

Foreach ($element in $hosts){
Resolve-DnsName $element 

}

 Get VAAI Plugin status

Get-VMHost | Get-AdvancedSetting -Name DataMover.HardwareAccelerated*, VMFS3.HardwareAccelerated* | Select-Object Entity,Name,Value | Sort-Object Entity

 Get time server status

Get-VMHost | Sort Name | Select Name, @{N=“NTPServer”;E={$_ |Get-VMHostNtpServer}}, ` Timezone,

@{N=“CurrentTime”;E={(Get-View
$_.ExtensionData.ConfigManager.DateTimeSystem) | Foreach {$_.QueryDateTime().ToLocalTime()}}}, `

@{N=“ServiceRunning”;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq “ntpd”}).Running}} `

Facebooktwittergoogle_pluslinkedinby feather

Deploying vCenter 6 Appliance (VCSA) from ISO

So just a quick run through on how to deploy the vCenter Virtual Appliance. You’ll need to obviously get the VCSA ISO, and then pre-create the DNS settings for the new vCenter.

OK so now you have the ISO mount it and you will need to install the VMWare Client Integration Plugin which is included on the ISO

The installer is pretty much just a next, next finish! You will need to accept the EULA, and accept the installation location (or specify a new one should you desire)

OK once the Plugin has installed we can crack on with the vCenter Installation

Browse to the root of the ISO and click on the vcas-setup.html file

You may need to allow the Integration Plugin to allow in the browser but as long as it install OK you should be greeted with the following page

As I am performing a new installation I select “Install”

Accepts the EULA

Specify the host (FQDN or IP) of where you want to deploy the vCenter Appliance

Accept the certificate

Specify the appliance name and the root password

As this deployment is for my home lab I am going to deploy the vCenter Server with an Embedded Platform Services Controller

Configure you SSO Domain and Password

And then configure your appliance size, I am using “Tiny” deployment for my home lab

Select your data store

Select you database, currently the vCenter Appliance on supports Oracle as an external database, and I’ll be using the embedded database for my lab

Configure your network

Check your summary and then click finish

Let the installer complete and voila!!! You have deployed your vCenter 6 Appliance

 

NOTE!!! After I had deployed my appliance I had some issues with adding the appliance to the domain the error I was getting was

Idm client exception: Error trying to join AD, error code [11], user

For a resolution to this issue, visit this fantastic blog, I ran through this and low and behold it worked a treat.

https://mattwhiteccie.wordpress.com/2015/03/31/fighting-with-windows-2012-r2-directory-services-netbios-naming-vcenter-6-0-sso-on-vcsa/comment-page-1/#comment-4

 

Facebooktwittergoogle_pluslinkedinby feather

PowerCLI Get Free Disk Space info from VMs

This script exports all information regarding free disk space on all VMs on your vCenter. This will only work on Powered on VM’s with VMTools installed and running.

 
Add-PSSnapin VMware.VimAutomation.Core

Connect-VIServer -Server vCenterServer

$MyCollection = @() 

$AllVMs = Get-View -ViewType VirtualMachine | Where {-not $_.Config.Template} 

$SortedVMs = $AllVMs | Select *, @{N="NumDisks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks

ForEach

 ($VM in $SortedVMs){ 

$Details = New-object PSObject

$Details | Add-Member -Name Name -Value $VM.name -Membertype NoteProperty

$DiskNum = 0

Foreach ($disk in $VM.Guest.Disk){ 

$Details | Add-Member -Name "Disk$($DiskNum)path" -MemberType NoteProperty -Value $Disk.DiskPath 

$Details | Add-Member -Name "Disk$($DiskNum)Capacity(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.Capacity / 1MB)) 

$Details | Add-Member -Name "Disk$($DiskNum)FreeSpace(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB)) 

$Details | Add-Member -Name "Disk$($DiskNum)Free%" -MemberType NoteProperty -Value ("{0:p2}" -f ($disk.FreeSpace / $disk.Capacity)) 

$DiskNum++

 } $MyCollection += $Details

}

$MyCollection | Export-Csv -NoTypeInformation "C:\FreeDiskSpaceInfo.csv" 


Facebooktwittergoogle_pluslinkedinby feather

List vSphere Datastores with less than 20% Free Space

The below script lists all datastores with less than 20% free space:


Connect-VIServer -Server vCenterName

function CalcPercent {
param(
[parameter(Mandatory = $true)]
[int]$InputNum1,
[parameter(Mandatory = $true)]
[int]$InputNum2)
$InputNum1 / $InputNum2*100
}

$datastores = Get-Datastore | Sort Name
ForEach ($ds in $datastores)
{
if (($ds.Name -match "Shared") -or ($ds.Name -match ""))
{
$PercentFree = CalcPercent $ds.FreeSpaceMB $ds.CapacityMB
$PercentFree = "{0:N2}" -f $PercentFree
$ds | Add-Member -type NoteProperty -name PercentFree -value $PercentFree
}
}
$datastores | where-object {$_.PercentFree -le 20} | Select Name,FreeSpaceGB,CapacityGB,PercentFree
Facebooktwittergoogle_pluslinkedinby feather