Clearing out missing pool desktop

if a desktop goes missing after a recompose, newer verions of Horizon have a tool to help out so you don’t have to go into the ADAM database and manually edit things.

go into the horizon server and the following directory. and follow the steps

cd c:\Program Files\VMware\VMware View\Server\tools\bin
viewdbchk.cmd –scanMachines –limit 100

You will have to enter the view user password as well as the composer password.
this will ask to disable the pool, say yes (make sure you have a maintenance window) and then it will ask to re enable once done.

checking cluster enic fnic and driver vers



Get the enic and fnic and check for any drivers that are NOT the VMware ones.

$vmhs = Get-Cluster dc1-clv07 | Get-VMHost | sort Name
foreach ($vmh in $vmhs){
Write-Host $vmh.Name " - " $vmh.build -ForegroundColor Blue
#$vmh = Get-VMHost "ral-dev-esx27.rd.allscripts.com"
$esxcli = Get-EsxCli -VMHost $vmh
$face = $esxcli.software.vib.list()
$face | where {$_.Vendor -ne "VMware"} | ft Name,Vendor,Version
$esxcli.system.module.get("enic").version
$esxcli.system.module.get("fnic").version
Write-Host ""
}

how to make an iso with the latest image!

ever wanted to make an ISO with the latest stuff so no need to reinstall or reupdate the host?

Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml
Get-EsxImageProfile ESXi-5.1.0-20130304001-standard | Export-EsxImageProfile -ExportToIso -FilePath C:\AlanTemp\esx51latest.iso

copy templates!

[powershell]
Connect-VIServer *
$st = nas
$fold = "Nas_Templates"
$datasto = "z) nasvm01*"
$ho = "nasvm01*"

$spec = New-Object VMware.Vim.VirtualMachineCloneSpec

$folder = (Get-Folder $fold | Get-View)
$data = (Get-Datastore $datasto | Get-View)
$hos = (Get-VMHost $ho | get-view)

#$folder = New-Object VMware.Vim.ManagedObjectReference
#$folder.type = "Folder"
#$folder.value = "group-v12744"

$spec.location = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.location.datastore = New-Object VMware.Vim.ManagedObjectReference
$spec.location.datastore.type = "Datastore"
$spec.location.datastore.value = $data.moref.value
$spec.location.host = New-Object VMware.Vim.ManagedObjectReference
$spec.location.host.type = "HostSystem"
$spec.location.host.value = $hos.moref.value
$spec.location.transform = "sparse"
$spec.template = $true
$spec.powerOn = $false

$_this = Get-View -Id ‘VirtualMachine-vm-12257’
$_this.CloneVM_Task($folder.moref, "_nas_template_2008_STD32", $spec)

$_this = Get-View -Id ‘VirtualMachine-vm-12259’
$_this.CloneVM_Task($folder.moref, "_nas_template_2003_STD32", $spec)

$_this = Get-View -Id ‘VirtualMachine-vm-12348’
$_this.CloneVM_Task($folder.moref, "_nas_template_2008R2_STD", $spec)

$_this = Get-View -Id ‘VirtualMachine-vm-12697’
$_this.CloneVM_Task($folder.moref, "_nas_template_2008_STD64", $spec)
[/powershell]

Copy vSwitches and Portgroups to everybody in a cluster (like a boss)

Does just what it says, set up one host, and copys everything to the rest of the host, helps me set stuff up faster 🙂

#alan harrington, copy networking one host to another.
Connect-VIServer vcenter.www.alanrocks.com
$src = Read-Host "Please enter the golden host for networking: "
$destclu = Read-Host "Please enter the name of the cluster to copy too: "
foreach ($dest in (get-cluster $destclu | Get-VMHost)){

$desthost = Get-VMhost $dest
get-vmhost $src | Get-VirtualPortGroup | select VirtualSwitchName,Name,VLanId | export-csv c:\hostnetworking.txt -NoTypeInformation
$infohizzle = import-csv c:\hostnetworking.txt | where-object {$_.name -notmatch "vmotion" -and $_.name -notmatch "VMkernel" -and $_.name -notmatch "Service" -and $_.name -notmatch "Management Network"}

$infohizzle | % {
$Vportgrp = $_.Name
$vswitch = $_.VirtualSwitchName
$vlan = $_.VlanId

If (($desthost |Get-Virtualportgroup -Name $Vportgrp -ErrorAction SilentlyContinue)-eq $null){
if (($desthost |Get-VirtualSwitch -Name $vswitch -ErrorAction SilentlyContinue)-eq $null){$desthost | New-VirtualSwitch -Name $vswitch}
$desthost | Get-VirtualSwitch -Name $vswitch | New-VirtualPortGroup -ErrorAction "SilentlyContinue" -Name $Vportgrp -VLanId $vlan}}}

EON Stuff for vmware, and storage for opensolaris

EON rocks, its kinda hard to setup, but its freaking rock solid and has dedup

#########test wont work will later

mount -t nfs 192.168.1.19:/zfs-hybrid/vms /mnt
zpool iostat -v zfs-hybrid 5

How do I start NFS server services?
First, import the services
cd /var/svc/manifest/network
svccfg -v import rpc/bind.xml
svccfg -v import nfs/status.xml
svccfg -v import nfs/nlockmgr.xml
svccfg -v import nfs/mapid.xml
svccfg -v import nfs/server.xml
Then, enable them
svcadm enable -r nfs/server
or individually
svcadm enable rpc/bind
svcadm enable nfs/status
svcadm enable nfs/nlockmgr
svcadm enable nfs/mapid
svcadm enable nfs/server
##########BASICSSSS

#finds all the disk
hd
#makes partitions for the slog l2arc/zil
format

zpool create zfs-hybrid raidz c1d0p0 c2d0p0 c5d0p0 c6d0p0

zfs create zfs-hybrid/vms

zfs set compression=on zfs-hybrid
zfs set dedup=on zfs-hybrid

zfs set sharenfs=on zfs-hybrid/vms

zfs set sharenfs=rw,nosuid,root=192.168.1.41:192.168.1.42:192.168.1.51 zfs-hybrid/vms

@########advance

zpool add zfs-hybrid log /dev/dsk/c3d0p1
zpool add zfs-hybrid cache /dev/dsk/c3d0p2

zfs create -V 500G -b=128k pool/name
itadm create-initiator iqn.1991-05.com.microsoft:mailbox01-node1.flinetech.ca
sbdadm create-lu /dev/zvol/rdsk/zsan00store/mbx01-node1
stmfadm create-hg zsan00server-hg
stmfadm add-hg-member -g zsan00server-hg iqn.1991-05.com.microsoft:mailbox01-node1.flinetech.ca
stmfadm create-tg tg-mbx0-node0

itadm modify-target -n iqn.1986-03.com.sun:02:mbx01-node01 iqn.1986-03.com.sun:02:4b6f1bdc-86ca-611d-92eb-d840016fab80
stmfadm add-tg-member -g tg-mbx0-node0 iqn.1986-03.com.sun:02:mbx01-node01
stmfadm add-tg-member -g tg-mbx0-node0 iqn.1986-03.com.sun:02:mbx01-node01

stmfadm add-view -h zsan00server-hg -t tg-mbx0-node0 -n 1 600144F0CC12CC0000004A9036D30001
stmfadm list-view

stmfadm create-hg test-hg

itadm create-initiator iqn.1998-01.com.vmware:esx-02-0b27d1f5
itadm create-initiator iqn.1998-01.com.vmware:esx-01-0d95e7a9

stmfadm add-hg-member -g test-hg iqn.1998-01.com.vmware:esx-02-0b27d1f5
stmfadm add-hg-member -g test-hg iqn.1998-01.com.vmware:esx-01-0d95e7a9
stmfadm create-tg esx

#itadm create-target
iqn.1986-03.com.sun:02:21b5da92-8eae-4c74-a214-8a1d29c7ee72

itadm modify-target -n iqn.1986-03.com.sun:02:esx-vol1 iqn.1986-03.com.sun:02:8fba33b4-5e51-ea80-a5fc-d4364afd16b1
itadm modify-target -n iqn.1986-03.com.sun:02:esx-vol1 iqn.1986-03.com.sun:02:21b5da92-8eae-4c74-a214-8a1d29c7ee72

stmfadm add-tg-member -g esx iqn.1986-03.com.sun:02:esx-vol1

stmfadm add-view -h test-hg -t esx -n 1 600144f0998dc30000004bb0ed7d0001

stmfadm list-view -l 600144f0998dc30000004bb0ed7d0001

itadm create-initiator iqn.1998-01.com.vmware:esx-01-0d95e7a9
stmfadm add-hg-member -g test-hg iqn.1998-01.com.vmware:esx-01-0d95e7a9

$#@#@#@##@@
#fix after power outage!
stmfadm list-lu -v
stmfadm import-lu /dev/zvol/rdsk/zfs/iscsi

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.www.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]