VMware Cloud Community
Michelle_Laveri
Virtuoso
Virtuoso

How to get the moref value for an ESX host

Part of a powershell script I'm writing requires the ESX host moref value... like this:

host-746

I've found away of finding the moref value with:

$vmhost = "esx4.vi4book.com"

$esxhost = Get-VMHost $vmhost

$hostview = $esxhost | Get-View

$hostview.moref

But when I insert $hostview.moref into the method i'm using it returns an error... I think it because $hostview.moref doesn't return just the moref value but other parameters as well, and need away of just present the raw value - host-746...

Any ideas?

Regards

Mike Laverick

RTFM Education

http://www.rtfm-ed.co.uk

Author of the SRM Book: http://www.lulu.com/content/4343147

Regards
Michelle Laverick
@m_laverick
http://www.michellelaverick.com
0 Kudos
25 Replies
Michelle_Laveri
Virtuoso
Virtuoso

(That would be nice to see - Carter's demo).

In one respect it's quite gratifying that I got the main part of the script right. It suggest that I am very slowly getting used to navigating around the SDK - which isn't the most intuitive thing to do on the planet...

On separate note. I notice Stu was saying that he intermitent issue with making the script work. I found if I merely attached to the ESX host and ran the PS, then it hated it...

However, if I ran the script AFTER I'd used the add-host cmdlet, it worked....

So one thing seems clear. That to configure DPM the host must be in vCenter first. Added my ESX host to a DRS cluster (not DPM enabled by the way) and found that the script work even if DPM hadn't been enabled on the cluster...

The way I'm doing my configuration is - I attach directly to the ESX host and pop it into maintenance mode. I do everything I need to do (vswitches, iscsi, nas, ntp - the usual suspects), then I add the host to vCenter. Leaving it in maintenance mode - with the option to exit if everything is good. This way an ESX host doesn't become a target for VMs until someone manually verifies the PS has worked correctly... What I'm doing is pretty crude, and I'm trying to write the powershell in a "dummies" way so anyone reading it can see right away what it's doing... in effort to make the move away from esxcfg-commands to PS as painless as possible...

Regards

Mike Laverick

RTFM Education

http://www.rtfm-ed.co.uk

Author of the SRM Book: http://www.lulu.com/content/4343147

Regards
Michelle Laverick
@m_laverick
http://www.michellelaverick.com
0 Kudos
Michelle_Laveri
Virtuoso
Virtuoso

Oh, BTW stu... here's the blog post...

http://www.rtfm-ed.co.uk/?p=1621

Put a swear word into the post to keep you happy Smiley Happy

Regards

Mike Laverick

RTFM Education

http://www.rtfm-ed.co.uk

Author of the SRM Book: http://www.lulu.com/content/4343147

Regards
Michelle Laverick
@m_laverick
http://www.michellelaverick.com
0 Kudos
sradnidge
Enthusiast
Enthusiast

ROFL!!!!

Thanks for that, you really are too kind Smiley Happy

I initially got caught out with the direct host connection too, this is one of those wierd settings that is relevant only to a cluster (and therefore is a construct of vCenter rather than a host), but yet is defined in a host property. This is a little contradictory, for example with DPM in mind you would think that configuring the HA related isolation response settings of a VM would be a property of the VM, but it's not - there's an array that is a property of the cluster, and depending on what setting you configure a VM will or won't appear in that array. So I was expecting the same for the DPM settings, and was surprised when it actually was a host property.

Just one of those quirks I guess, part of the joy of stumbling your way around the SDK - which you are obviously doing as well as any of us these days Smiley Happy

Stu

0 Kudos
fixitchris
Hot Shot
Hot Shot

If the truth is that System.String is parsed by the Vmware sdk, then you could try 0` at the beginning or end of the string.

$password = "0`pass"

$passwrod = "pass0`"

0 Kudos
s33butler
Contributor
Contributor

when using the script I receive an error...

C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> $esx

MoRef.UpdateIpmi($IpmiInfo)

Exception calling "UpdateIpmi" with "1" argument(s): "The operation is not supp

orted on the object."

At line:1 char:21

+ $esxMoRef.UpdateIpmi <<<< ($IpmiInfo)

+ CategoryInfo : NotSpecified: (Smiley Happy [], MethodInvocationException

+ FullyQualifiedErrorId : DotNetMethodException

But I'm unable to find any useful info on the error, has anyone run into this or can guid me as to what I am doing wrong?

Thank you for your time and assistance,

Scott

0 Kudos
Michelle_Laveri
Virtuoso
Virtuoso

This is what I wrote and works for me:

$vmhost = "esx4.vi4book.com"

$login = "vmware_dpm_user"

$password = "password"

$hostview = get-vmhost $vmhost | % {Get-View $_.Id}

$IpmiInfo = New-Object Vmware.Vim.HostIpmiInfo

$IpmiInfo.BmcIpAddress = “192.168.3.204″

$IpmiInfo.BmcMacAddress = “00:16:35:37:F8:02″

$IpmiInfo.Login = $login

$IpmiInfo.Password = $password

$hostview.UpdateIpmi($IpmiInfo)

Regards

Mike Laverick

RTFM Education

http://www.rtfm-ed.co.uk

Author of the SRM Book:http://stores.lulu.com/rtfm

Free PDF or at-cost Hard Copy

Regards
Michelle Laverick
@m_laverick
http://www.michellelaverick.com
0 Kudos