find stupid 100 meg links

Get-VMHost | Get-VMHostNetworkAdapter | where {$_.BitRatePerSec -eq “100”} | fl VMhost,BitRatePerSec,DeviceName

Get-VMHost | Get-VMHostNetworkAdapter | where {$_.BitRatePerSec -eq "100"} | fl VMhost,BitRatePerSec,DeviceName

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.
$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 {$ -notmatch "vmotion" -and $ -notmatch "VMkernel" -and $ -notmatch "Service" -and $ -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}}}

Stupid board – zfs could be faster

pci, instance #0
pci1028,20e (driver not attached)
isa, instance #0
motherboard (driver not attached)
pit_beep, instance #0
pci1028,20e (driver not attached)
pci1028,20e (driver not attached)
pci1028,20e, instance #0
keyboard, instance #0
mouse, instance #1
pci1028,20e, instance #0
pci10de,3f3, instance #0
pci-ide, instance #0
ide (driver not attached)
ide (driver not attached)
pci-ide, instance #1
ide, instance #2
cmdk, instance #2
ide, instance #3
cmdk, instance #3
pci-ide, instance #2
ide, instance #4
cmdk, instance #0
ide, instance #5
cmdk, instance #1
pci10de,3e8, instance #0
pci1166,103, instance #2
pci14e4,164c, instance #0
pci10de,3e9 (driver not attached)

nice, i’ve been running in ide mode this whole time, no ncq without sata. fuckers.

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 /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

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

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= zfs-hybrid/vms


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
sbdadm create-lu /dev/zvol/rdsk/zsan00store/mbx01-node1
stmfadm create-hg zsan00server-hg
stmfadm add-hg-member -g zsan00server-hg
stmfadm create-tg tg-mbx0-node0

itadm modify-target -n
stmfadm add-tg-member -g tg-mbx0-node0
stmfadm add-tg-member -g tg-mbx0-node0

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

stmfadm create-hg test-hg

itadm create-initiator
itadm create-initiator

stmfadm add-hg-member -g test-hg
stmfadm add-hg-member -g test-hg
stmfadm create-tg esx

#itadm create-target

itadm modify-target -n
itadm modify-target -n

stmfadm add-tg-member -g esx

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

stmfadm list-view -l 600144f0998dc30000004bb0ed7d0001

itadm create-initiator
stmfadm add-hg-member -g test-hg

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

Finding stuff in all the cool datastores you never knew you had (or that you knew you had, you just really didn’t want to click alot)

Lucd has been my number one source of scripts for pretty much like ever. He is always willing to helping out in the community, uber smart and knows his stuff. I often will use his scripts to start and do something else with them, mostly because I don’t know how, and I am lazy. his most awesome script was something that i started to do, and did back in bash in the good ol esx days, since esx pretty much is dead (it’s about freaking time), i needed to convert it PS to make it work, but low and behold, he already did it.

Here. Raiders of the lost VMX

These things are amazing for scripting DR when the client just isn’t big enough to justify SRM

Anywho how this started is I recently had a client’s site the VDR appliance blow up and start making snapshot files with failing the snapshot, since it failed it never removed the vmsn files, and it was only on a few particular datastores. I am not gonna name names, but I’m 99% sure it had to do with the buggy 5.0.1 equallogic firmware and its Atomic Lock and Set, but now that that is fixed its pretty freaking awesome.
so with the permission of LucD himself, here is the modified script to look for vmsn files plus all the other cool stuff it could do beforehand!

without more delay, here it is!
function Register-VMX {
param($entityName = $null,$dsNames = $null,$template = $false,$ignore = $null,$checkNFS = $false,$whatif=$false,$snapshot = $false)

function Get-Usage{
Write-Host "Parameters incorrect" -ForegroundColor red
Write-Host "Register-VMX -entityName -dsNames [,…]"
Write-Host "entityName : a cluster-, datacenter or ESX hostname"
Write-Host "dsNames : one or more datastorename names"
Write-Host "ignore : names of folders that shouldn’t be checked"
Write-Host "template : register guests ($false)or templates ($true) – default : $false"
Write-Host "checkNFS : include NFS datastores – default : $false"
Write-Host "whatif : when $true will only list and not execute – default : $false"
Write-Host "snapshot : finds vmsn files if set to ($true) – default : $false"

if($entityName -ne $null -and $dsNames -ne $null){

if($dsNames -eq $null){
switch((Get-Inventory -Name $entityName).GetType().Name.Replace("Wrapper","")){
$dsNames = Get-Cluster -Name $entityName | Get-VMHost | Get-Datastore | where {$_.Type -eq "VMFS" -or $checkNFS} | % {$_.Name}
$dsNames = Get-Datacenter -Name $entityName | Get-Datastore | where {$_.Type -eq "VMFS" -or $checkNFS} | % {$_.Name}
$dsNames = Get-VMHost -Name $entityName | Get-Datastore | where {$_.Type -eq "VMFS" -or $checkNFS} | % {$_.Name}
$dsNames = Get-Datastore -Name $dsNames | where {$_.Type -eq "VMFS" -or $checkNFS} | % {$_.Name}

$dsNames = $dsNames | Sort-Object
$pattern = "*.vmx"
$pattern = "*.vmtx"
$pattern = "*.vmsn"

foreach($dsName in $dsNames){
Write-Host "Checking " -NoNewline; Write-Host -ForegroundColor red -BackgroundColor yellow $dsName
$ds = Get-Datastore $dsName | Get-View
$dsBrowser = Get-View $ds.Browser
$dc = Get-View $ds.Parent
while($dc.MoRef.Type -ne "Datacenter"){
$dc = Get-View $dc.Parent
$tgtfolder = Get-View $dc.VmFolder
$esx = Get-View $ds.Host[0].Key
$pool = Get-View (Get-View $esx.Parent).ResourcePool

$vms = @()
foreach($vmImpl in $ds.Vm){
$vm = Get-View $vmImpl
$vms += $vm.Config.Files.VmPathName
$datastorepath = "[" + $ds.Name + "]"

$searchspec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchspec.MatchPattern = $pattern

$taskMoRef = $dsBrowser.SearchDatastoreSubFolders_Task($datastorePath, $searchSpec)

$task = Get-View $taskMoRef
while ("running","queued" -contains $task.Info.State){
foreach ($folder in $task.Info.Result){
if(!($ignore -and (&{$res = $false; $folder.FolderPath.Split("]")[1].Trim(" /").Split("/") | %{$res = $res -or ($ignore -contains $_)}; $res}))){
$found = $FALSE
if($folder.file -ne $null){
foreach($vmx in $vms){
if(($folder.FolderPath + $folder.File[0].Path) -eq $vmx){
$found = $TRUE
if (-not $found){
if($folder.FolderPath[-1] -ne "/"){$folder.FolderPath += "/"}
$vmx = $folder.FolderPath + $folder.File[0].Path
Write-Host "`t" $vmx
write-host " Snapshot file found" -ForegroundColor blue -BackgroundColor white
$params = @($vmx,$null,$true,$null,$esx.MoRef)
$params = @($vmx,$null,$false,$pool.MoRef,$null)
if((!$whatif) -and (!$snapshot)){
$taskMoRef = $tgtfolder.GetType().GetMethod("RegisterVM_Task").Invoke($tgtfolder, $params)
Write-Host "`t" $vmx "registered"
Write-Host "`t" $vmx "registered" -NoNewline; Write-Host -ForegroundColor blue -BackgroundColor white " ==> What If"
Write-Host "Done"

# Register-VMX -entityName "MyDatacenter" -snapshot:$true
# Register-VMX -entityName "MyDatacenter"
# Register-VMX -dsNames "datastore1","datastore2"
# Register-VMX -dsNames "datastore1","datastore2" -template:$true
# Register-VMX -entityName "MyDatacenter" -ignore "SomeFolder"
# Register-VMX -dsNames "datastore3","datastore4" -ignore "SomeFolder" -checkNFS:$true
# Register-VMX -entityName "MyDatacenter" -whatif:$true

One Liners, We All Love Them

Finds all the vm’s with a cd-rom connected and disconnects them

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*
foreach ($d in (get-vm zT*)){$vm2 = Get-VM $d | Get-View; $vm2.MarkAsTemplate()}

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

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

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}}

Disable vMotion All the host in a cluster

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

Powershell Service Checks – VMware edition

# be tidy – clear the screen 🙂

# 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."
# 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{ (($ -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 = ""
# the service was found so get the service’s name
$isServiceFound = $

# check to see if any service names were returned
if ($isServiceFound -eq "")
# the service wasn’t found
$resultDisplay = "Not found"
# 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
# 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{ (($ -eq $serviceName) -or ($_.displayname -eq $serviceName))}
$serviceStatus2 = get-service $isServiceFound
$resultDisplay2 = $serviceStatus2.status
$smtpServer = ""
$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"
$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"


# 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 ""