One Liners, We All Love Them

CD-Rom
Finds all the vm's with a cd-rom connected and disconnects them

[powershell]
Get-VM | Where-Object {$_ | Get-CDDrive | Where-Object { $_.ConnectionState.Connected -eq "true" } } | Get-CDDrive | Set-CDDrive -Connected $false -Confirm:$false[/powershell]

Mark the vm's starting with zT as a template*
[powershell]
foreach ($d in (get-vm zT*)){$vm2 = Get-VM $d | Get-View; $vm2.MarkAsTemplate()}
[/powershell]

Deletes all Snapshots over 2 days old
[powershell]foreach ($snap in (Get-VM | get-snapshot)){if ($snap.Created -lt (Get-Date).AddDays(-2)){Remove-Snapshot $snap -Confirm:false}}[/powershell]

Connects all VM's with a certain name to the same iso

[powershell]
get-datacenter dc | get-cluster cl | get-vm 2008* | get-cddrive | set-cddrive -IsoPath "[Datastore Name] -isoname.iso" -Connected:$true -Confirm:$false[/powershell]

Let's Find the HAL level for vm's

[powershell]
Get-VM |Where {$_.PowerState -eq “PoweredOn“} |Sort Name |Select Name, NumCPU, @{N=“OSHAL“;E={(Get-WmiObject -ComputerName $_.Name-Query “SELECT * FROM Win32_PnPEntity where ClassGuid = ‘{4D36E966-E325-11CE-BFC1-08002BE10318}’“ |Select Name).Name}}, @{N=“OperatingSystem“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select Caption).Caption}}, @{N=“ServicePack“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select CSDVersion).CSDVersion}}
[/powershell]

VMHost
Disable vMotion All the host in a cluster

[powershell]
get-datacenter DC | get-cluster CL | get-vmhost | set-vmhostadvancedconfiguration -Name Migrate.Enabled -Value 0
[/powershell]

Powershell Service Checks - VMware edition

[powershell]
# be tidy - clear the screen 🙂
cls

# show a welcome message
write-host "VMware Service Status"
write-host "--------------------"
write-host ""

function checkService ($serviceName, $machineName) {

# do some very basic error checking
if (($serviceName -eq $null) -or ($machineName -eq $null))
{
write-host "Service or machine name missing. Please correct and retry."
}
else
{
# use the .NET abilities of PowerShell to get a list of all services that match the service name we're looking for
# note that we are checking both the short and display names, i.e. you can check for either
# e.g. "iisadmin" and "IIS Admin Service" will both work
$serviceResults = [System.ServiceProcess.ServiceController]::GetServices($machineName) | where{ (($_.name -eq $serviceName) -or ($_.displayname -eq $serviceName))}

# check to see if the results is an empty object
# if it is empty the requested service wasn't found
if ($serviceResults -eq $null)
{
# the service wasn't found so set the result to an empty string (it's used later)
$isServiceFound = ""
}
else
{
# the service was found so get the service's name
$isServiceFound = $serviceResults.name
}

# check to see if any service names were returned
if ($isServiceFound -eq "")
{
# the service wasn't found
$resultDisplay = "Not found"
}
else
{
# the requested service was found so get its status
$serviceStatus = get-service $isServiceFound
$resultDisplay = $serviceStatus.status
}

# return the result of the service check
if ($resultDisplay -eq "Running")
{
# it is running so display an appropriate confirmation in normal text colour
write-host "$serviceName : " -noNewLine
write-host $resultDisplay
}
else
{
# the service isn't running to display a warning in red text colour
write-host "$serviceName : " -noNewLine
write-host $resultDisplay -foregroundColor('red')
Start-Service "$servicename"
Start-Sleep -s 45
$serviceResults2 = [System.ServiceProcess.ServiceController]::GetServices($machineName) | where{ (($_.name -eq $serviceName) -or ($_.displayname -eq $serviceName))}
$serviceStatus2 = get-service $isServiceFound
$resultDisplay2 = $serviceStatus2.status
$smtpServer = "exchange2010.alanrocks.com"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = "[email protected]"
$msg.To.Add("[email protected]")
$msg.Subject = "$serviceName Service ERROR"
$msg.Body = "Something Broke!!!!!"
$msg.Body += "`n `n$serviceName : $resultDisplay"
$msg.Body += "`n `n `n"
$msg.Body += "I have tried to start the service and "
if ($resultDisplay2 -eq "Running")
{
$msg.Body += "it is now running successfully"
$msg.Body += "`n $serviceName : $resultDisplay2"
Write-Host "I have tried to start the service $serviceName and is now running"
}
else
{
$msg.Body += "it is STILL NOT STARTED"
$msg.Body += "`n $serviceName : $resultDisplay2"
Write-Host "I have tried to start the service $serviceName and is STILL NOT running"
}

$smtp.Send($msg)
}
}
}

# this line dynamicaly loads the .NET assemblies into memory so they can be used by this script
$loadAssemblies = [System.Reflection.Assembly]::LoadWithPartialName('system.serviceprocess')

# setup the list of services we want to check
# modify this array to suit your needs
$serviceList = "SQL Server (SQLEXP_VIM)", "VMware VirtualCenter Server", "VMware VirtualCenter Management Webservices"

# loop through the list of services and check then report on the status of each one
foreach ($serviceEntry in $serviceList)
{
# try and get the service's status (if it exists)
checkService $serviceEntry 'localhost'
}

# not important, just for clean-screen reasons again 🙂
write-host ""
[/powershell]

IOP Testing and Shit

attaching a ssd to a zfs pool of a raidz made up of 4x500gb hd to use
as a zil resulted in a ~4.89x performance increase in a real world
VMware 60% rand 65% write access pattern, an ssd alone netted a ~10x
improvement. When more than one worker is assigned the iops on the HSP
remained at a constant performance level where as the standard pool
quickly dropped to unusable levels. When the main os was converted to
a usb device and the other ssd was split into two partions and used as
a read cache for the zfs system, and the zil for the raidz pool with
the ssd in its own pool, at relative 16x IOPs improvement was noticed.
when running multiple workloads from different NFS datastores

So anywho im now flooding the fucking pipes and need to lag. A VERY
cost effect upgrade ($260 bucks for a hell of a ROI and performance
increase)

WordPress Themes