SCVMM: Get List of Storage Hogging VMs by Volume

December 16, 2011

Lately a couple of our Cluster Shared Volumes have been hitting a high percentage of usage, to alleviate any issues, I wanted a simple way to find out which VMs had the largest disk usage on those volumes. I chose to query volumes that were over 70% usage and the top 5 storage hogging VMs from those.

Credit goes to this post as getting a proper output of the paths and percentage is a real pain with the Failover Clustering CMDLets.

function Get-LargestVMs {
function Get-LargeVMs ($Path) {
   $Size = get-vm -vmmserver "IP" | Where-Object {$_.vmcpath -like "*$Path*"} | Select Name,TotalSize,Hostname | Sort-Object TotalSize -Descending | Select-Object -First 5 | Out-String
   Write-Host $Size
}

$objs = @()

$csvs = Get-ClusterSharedVolume -Cluster "Cluster"
foreach ( $csv in $csvs )
{
   $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo
   foreach ( $csvinfo in $csvinfos )
   {
      $obj = New-Object PSObject -Property @{
         Path        = $csvinfo.FriendlyVolumeName
         PercentFree = $csvinfo.Partition.PercentFree
      }
      $objs += $obj
   }
}

$objs | foreach {
if ($_.PercentFree -ge "70")  {
   Write-Host "################################################"
   Write-Host $_.Path
   Write-Host "Current percent free is"$_.PercentFree
   Write-Host "################################################"
   Get-LargeVMs $_.Path
}
else {
}
}
}

Powershell: SCVMM Host Status Snippet

December 1, 2011

I changed this around in my last script to verify the operational status of a host via SCVMM instead of the Hyper-V server itself.

function CheckHostStatus	{
$HostState = Get-VMHost $VMHost
		if (($HostState.ComputerState -match "Responding") -and ($HostState.ClusterNodeStatus -match "Running") -and ($HostState.VirtualServerState -match "Running") -and ($HostState.VirtualServerStateString -match "Running") -and ($HostState.CommunicationStateString -match "Responding") -and ($HostState.CommunicationState -match "Responding")) {
		Write-Host "Host is operational"
										}
		Else    {
		Write-Host "Host is not fully operational"
		sleep 120
		CheckHostStatus
				}
							}

Hyper-V: Scripting Updates for Standalone Hosts

October 10, 2011

I’m now in charge of roughly 30 Hyper-V servers, half in an HA cluster, and the rest are standalone. Rather than doing updating each server manually I decided to take it upon myself to automate it via PowerShell. In my environment, we use SCVMM and SCOM, so doing this is rather easy, we also have WSUS for filtering updates as we have run into a few issues before.

There are 2 pieces of software used in this as a workaround for a known issue with remotely calling the Microsoft Update Session API, WUInstall and PSexec.

Here is the code below:

 

Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client

$VMMServer = Get-VMMServer "SCVMM IP Adress"    #<- Had issues with authentication while using the FQDN

$SCOMServer = "SCOM Server FQDN"

$VMHosts = Get-VMHost -VMMServer $VMMServer | Where-Object {$_.name -ge "Hostname"}

                New-PSDrive -Name:Monitoring -PSProvider:OperationsManagerMonitoring -Root:\ | Out-Null
                New-ManagementGroupConnection -ConnectionString:$SCOMServer | Out-Null
                Set-Location "Monitoring:\$SCOMServer"

function StartMaintenance       {
$SCOMAgent = Get-Agent | Where-object {$_.Name –match “$VMHost”}
                Write-Host "Placing host $VMHost into maintenance mode."
                $SCOMAgent.HostComputer | New-MaintenanceWindow -StartTime (Get-Date) -EndTime ([DateTime]::Now).AddMinutes(60) -Comment "Running Windows Updates"
                Disable-VMHost $VMHost | Out-Null
                                                        }

function EndMaintenance {
$SCOMAgent = Get-Agent | Where-object {$_.Name –match “$VMHost”}
                Write-Host "Placing host $VMHost back into service."
                Enable-VMHost $VMHost | Out-Null
                $SCOMAgent.HostComputer | Set-MaintenanceWindow -EndTime ([DateTime]::Now).AddSeconds(5) -Comment "Finished Windows Updates"
                                                }

function InstallUpdates {
                psexec \\$VMHost -s -c \\shareserver\share\wuinstall.exe /install /accepteula > "C:\Users\logon\Desktop\Scripts\Logs\$VMHost.log"
                        }

function CheckForReboot {
$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$VMhost)
$key = $baseKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\")
$subkeys = $key.GetSubKeyNames()
$key.Close()
$baseKey.Close()
                If ($subkeys | Where {$_ -eq "RebootPending"})  {
                Write-Host "Reboot is required: Restarting $VMHost"
                Restart-Computer -ComputerName $VMHost -Force
                sleep 120
                                                                                                                }
                Else    {
                Write-Host "No Reboot required."
                                }
                        }

function CheckVMStatus  {
$VMStatus = Get-VM -VMMServer $VMMServer -VMHost $VMHost | Select Status
                if ($VMStatus -match "HostNotResponding")       {
                Write-Host "SCVMM has not updated the status of the Virtual Machines yet"
                sleep 120
                CheckVMStatus
                                                                                                                }
                Else    {
                Write-Host "Powering on Virtual Machines"
                Get-VM -VMMServer $VMMServer -VMHost $VMHost | Start-VM | Out-Null
                                }
                        }

function CheckHostStatus        {
$Status = Get-Service -Computername $VMHost VMMS -erroraction silentlycontinue | select status
                if ($Status -match "Running")   {
                Write-Host "Host is Up"
                Write-Host "Waiting for SCVMM to populate VM state"
                CheckVMStatus
                                                                                }
                Else    {
                Write-Host "Host is still rebooting"
                sleep 120
                CheckHostStatus
                                }
                                                        }
Foreach ($VMHost in $VMHosts)   {
                StartMaintenance
                InstallUpdates
                CheckForReboot
                CheckHostStatus
                EndMaintenance
                                }

Perfect vSphere 5 whitebox

August 25, 2011

I was hunting for a new affordable whitebox all pieced together for me, IE a desktop that was inline with the HCL. I looked through Best Buy since they usually have decent deals and went to my local CompUSA store to scope things out. I ended up buying a Gateway DX4860 from Best Buy for just a bit over 600 with tax included.

What you get:

i5 Quad 2.8ghz CPU
8gb RAM(Max 16gb)
1tb Hard Drive
6 SATA Ports
Realtek 100/1000 NIC(Now supported during stock installation!)

vCenter 5: The FQDN cannot be resolved.

August 24, 2011

I was lucky enough to grab a copy of the vSphere 5 suite this weekend. Upgrade went fine, but I encountered an error during the install process for vCenter 5 stating “The Fully Qualified Domain Name could not be resolved”, after doing some testing I had no issue resolving that to my IP address assigned to the server, I was a bit confused at it but I clicked OK though it and the install worked fine. Later that day I decided to migrate one of my VM’s over to another datastore, but I encountered an error stating “Could not connect to host”, this also seemed to have affected deploying templates too. After much troubleshooting and digging, I found @2vcp‘s post, which at the very end stated I would need a PTR record, after adding this everything worked like a charm. What working at a hosting company has taught me is that 90% of the issues are either permissions or DNS related.

UPDATE:

I previously didn’t have a host within my own network, only the vCenter server. Upon having this issue happen again “Cannot connect to host” when deploying templates or migrating data, I found out that this was caused by TCP port 902 not being opened on my firewall. As previously posted, I have another machine outside of my network, so in order for that to work, I have to set my managed IP to my ISP provided IP. The hosts inside the network also rely on this and not the internal IP, once I made a rule to forward that port to my ESXi host, everything worked as normally. I’m sure I thought I fixed the issue, because the first time I tried fixing the FQDN issue, I had uninstalled/reinstalled vCenter and removed the vCenter agent, I can only think that the vpxa.cfg was never updated with the managed IP address.

Locking yourself out of vCenter

August 22, 2011

A few days ago, I was browsing through Reddit and saw this post, where it was suggested that the person edit their database or vpxd.cfg to fix this issue via this article from years ago by Eric Sloof. There is a much simpler way of remedying this issue. vCenter takes its base permissions from the Administrators group on the vCenter server, this group is the local group which contains both domain users/groups AND local users/groups, therefore using the local administrator account or any account in this group, you could edit the Domain Users group from being Read Only.

 


Stepping into the Cloud

August 17, 2011

I’ve finally made it, Cloud 9. Starting a few days ago, I am now one of the main virtualization administrators in our Tampa office, which hosts our eastern cloud services cluster for Hostway. I will be supporting our Hyper-V cluster , VMware vSphere environments for some of our VIP customers, and all of the other goodies a regular system administrator would handle. This is going to be a great learning experience and probably make my head explode shortly.

2X ApplicationServer XG

August 2, 2011

I came across this software last week when looking for another viable RDP client for OSX, since CoRD has been having some stability issues in Lion. To my surprise I found 2X ApplicationServer XG, which is much like RemoteApp from what I’ve seen, one of the key differences is that it has clients for OSX, iOS, Linux and of course Windows. You can grab a copy at their site, it’s completely free for personal use, I think you get 3 connections with the free license. Since it runs off of Microsoft Terminal Services, you’ll need to install it on a 2003 or 2008 server. Here are a few screenshots:

 

 

 

 

 

pfSense and NATing with vSphere

May 6, 2011

After getting my server setup in our datacenter, I had to think of a way to not use all of my 5 allocated IP addresses. pfSense came to mind as I heard of it before. This neat little piece of software can do a ton of different things, in my case, NATing and routing.

pfSense provides a VMware ready image, I actually had to use Converter to send it over to my host for it to import correctly, otherwise adding it to inventory would bring up a bad machine.

Once that is done, you’ll want to set up a vSwitch with no assigned NIC like the following:

Because the end VM will have 2 NICs on 2 different networks and 2 MAC addresses, get a pen down and write which is which, as you’ll need to know during the configuration to set up WAN and LAN connections.



Now we’re at the point where we need to get into the OS. After this prompt it will then ask you which device em0 or em1 will be the WAN NIC, then the LAN NIC, and their associated configurations.

One problem I found after this configuration is that I could not load the web frontend, apparently with this version, 2.0RC1, there is a bug with the default gateway. I had to press 8 for the Shell Prompt, and enter route add default x.x.x.x. This could either be an issue all around, or with the setup I had, as I was on a x.x.x.144/29 address scheme. After that, I was able to log into pfSense and add the gateways through the web interface, you can either do it when viewing the NIC’s settings or under System -> Routing:

Sometimes, you may need to add a route, under System -> Routing between the WAN and LAN for some reason. I’ve taken it out previously and things have worked, but when they break bad, sometimes I have to add it back, not sure why this would be necessary since the system should already know or atleast put this information in by default.

DNS is located under System -> General Setup and I simply added Google’s DNS server, 8.8.8.8.

Now there are a few gotchas, one is a major performance boost, the other is a major annoyance. First, disabling hardware checksum offload under System -> Advanced -> Networking provides a huge performance boost.

Lastly, the major annoyance is that sometimes, for unknown reasons, the LAN goes offline, resolving it is as simple as ifconfig em1 down then ifconfig em1 up. Other than that, it’s a great product, hopefully every bug I had will eventually be squashed.

Using vCenter behind a NAT

May 5, 2011

Well, I finally got my server up and running at our datacenter, I wanted to then hook it up a vCenter server running at my house. All seemed well, I got DNS and firewall ports all set, then finally connected my host to vCenter. Shortly after, to my dismay, my host suddenly disconnected. I tried reconnecting and it worked…then disconnected and so on. Thinking I missed a firewall port, or something DNS related was causing the issue, I googled all around and found nothing other than what I had already done, until yesterday.

I ended up finding this article here, which solved my problem promptly. Since I was at home, with a single IP address and my host being outside of my house on another network, I knew that the NAT had to be the issue now that I found this article. As the knowledge base explains, you need to set the managed IP address of the outside address of the NAT, which would be the IP my ISP gave me, this would have to be done on vCenter and later VMware Update Manager too.

It was rather easy in both instances. For vCenter, clicking Administration -> vCenter Server Settings then going to Runtime Settings and changing the vCenter Server Managed IP field as showed in the below screenshot.

For VMware Update Manager, you’ll need to go into the admin view and configuration. And update the IP address to your internet facing one, now that it’s added in vCenter, it’ll also show up here.

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org