ForwardOrReverse

Latest Posts

Get-VmDiskPersistenceReport

As part of our auditing process I need validate guest disk persistence settings. Here is a simple snippet to get the needed data.

1
2
3
4
Get-VM | ForEach-Object {
    $vmname = $_.Name
    $_.HardDisks | Select-Object @{Name="VM"; Expression={$vmname}}, Filename, Persistence
}

Get-PreviousWeekdayDate

I am fleshing out my automated monitoring/reporting system and I wanted to include some performance data exports. As part of this I always wanted my weekly exports to start on a certain day of the week no matter when the script was run. I also needed to make sure that I received a weeks worth of data.

To help out I wrote this function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Find the date of a previous weekday.  Originally conceived to export performance
# from a give day of the week no matter when it was called.
function Get-PreviousWeekdayDate
{
    param
    (
        [DateTime]$date = $(Get-Date),
        [System.DayOfWeek]$weekDay = $([System.DayOfWeek]::Sunday),  # Full weekday names work here.
        [switch]$fullWeek # The return date must be a full week ago.
    )
 
    Set-Variable -Name DAYS_IN_WEEK -Value 7 -Option Constant
 
    $dayDelta = 0 # The difference in days between $date and the target day.
 
    # If we are further in the week then we just go back x days.
    if ([Int32]$date.DayOfWeek -ge [Int32]$weekDay)
    {
        $dayDelta = [Int32]$date.DayOfWeek - [Int32]$weekDay
    }
    # Otherwise we need wrap around the week
    else
    {
        $dayDelta = $DAYS_IN_WEEK + [Int32]$date.DayOfWeek - [Int32]$weekDay
    }
 
    $date = $date.AddDays(-$dayDelta)
 
    # Go back 7 days 
    if ($fullWeek)
    {
        $date = $date.AddDays(-$DAYS_IN_WEEK)
    }
 
    $date
}

Report on HA Isolation Response

$desiredResponse = "DoNothing"
 
foreach ($cluster in Get-Cluster)
{
    $result = $cluster | Select-Object Name, HAIsolationResponse,
                             @{Name="DesiredResponse"; Expression={$desiredResponse}}
 
    if (!$cluster.HAEnabled)
    {
        $result.HAIsolationResponse = "HaNotConfigured"
    }
 
    $result
}

LoadVMs-FromFile

I was using the VMware VI Toolkit for Windows for a change and I needed to load VMs from a CSV and my typical stream oriented way of doing this was very inefficient over the WAN (or LAN really). There are many ways of making Get-VM operations faster, but for this change I decided to use the standard Get-VM cmdlet with an array of computer names instead of doing them one by one.

Below is the function I wrote to make this easier for repeated use. The csv should have the computer name under a ‘Name’ column heading. All other columns are ignored.

Example file
Field1,Name,Field3,FieldN
“”,”testvm01″,””,””
“”,”testvm02″,””,””

1
2
3
4
5
6
7
8
9
10
function LoadVMs-FromFile
{
    param
    (
    $file = $(throw "A file must be specified.")
    )
    $vmNames = @()
    Import-Csv $file | % {$vmNames += $_.Name}
    Get-VM $vmNames
}

VMFS creation error: Unable to read partition information from this disk.

When trying to add a VMFS volume in the VIC I received the message “Unable to read partition information from this disk.” I did not have an option to overwrite any data and could not continue. The SAN administrator said that the disk was presented the exact same way that another working LUN was.

At the console I figured out which device it was (esxcfg-vmhbadevs) and tested to see if I could read the partition table.  Here is what I got.

[me@vmhost me]$ sudo fdisk -l /dev/sdf

There is a valid AIX label on this disk.
Unfortunately Linux cannot handle these
disks at the moment.  Nevertheless some
advice:
1. fdisk will destroy its contents on write.
2. Be sure that this disk is NOT a still vital
part of a volume group. (Otherwise you may
erase the other disks as well, if unmirrored.)
3. Before deleting this physical volume be sure
to remove the disk logically from your AIX
machine.  (Otherwise you become an AIXpert).

Disk /dev/sdf: 543.0 GB, 543050956800 bytes
255 heads, 63 sectors/track, 66022 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End    Blocks   Id  System

It appears that the LUN was had remnants of a file system that the service console refused to deal with. All I really needed to do was destroy the information on the disk. There are many options for doing this, but the one I chose was to launch fdisk and write an empty DOS partition table by using the o command. A quick w(rite) and I could create a VMFS volume on the LUN.

Alternative solution to deployment issues when change Service Console IP

Host IP in vpxa.cfg retains old value after changing service console IP.

The VMware solution is:

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006768

The problem is that I did not want to lose my host’s historical information.  An alternative to removing and re-adding the host is to stop the Virtual Center service and update the VPX_HOST table in the Virtual Center database to contain the correct IP for the server(s).  When you start the service back up it will update the hosts configuration (vpxa.cfg) and everything should work again.

The query I used:

UPDATE VPX_HOST SET IP_ADDRESS = '10.11.12.13'
WHERE DNS_NAME = 'myvhost.localdomain.local'

VMware vSphere and Enterprise Plus

So here are the new editions.

Hmm.  My current Enterprise licenses will not give me the all of the feature of the new version.  There are a lot of angry blog posts out there on this new policy.  I do not know if I would consider myself angry, but I am disappointed and more than a little confused.

I understand that as new products come out (* Manager) I will be expected to pay extra for them.  They add a lot more value than the existing stack and I expect that.  In the case of new vSphere features VMware is introducing enhancements, but that is expected for a new product.

I do not understand being expected to pay more for something that is adding incremental value on a new product.  That is what the subscription is supposed to be for.

Here is a good write up of some other ramifications of this policy. VMware Slaps Enterprise and Cisco In Face, Opens Door For Competitors

VMware Converter p2v fails at 2%

My p2v was sticking at 2% and eventually failing.  Nothing was apparently wrong and a p2v worked yesterday to the same cluster.

Looking at the logs I ran across a message that led me to this forum post.  This was our problem too.  We had two NICs in a team – one was ok, but the other one had a duplex mismatch.  A quick change of active NICs and the p2v worked just fine.

Thanks Stridar for following up to your post with the resolution.

Secure Credential Storage

I have added some code to my Scripts/Programs page for securely storing credentials to disk to be used by scripts at a later time.

I explored the VI Credential cmdlets and I was not 100% happy with them so I decided to implement my own version that uses the Microsoft DPAPI for encryption.  Make sure to look at the README as it covers usage and current limitations.

I wrote these for use in some automated VMware monitoring I am doing, but there is no reason they have to be used with the VI Toolkit.  There are no dependencies on the toolkit.

Please provide feedback if you have any issues with the scripts.