VMware Cloud Community
Seasiderian
Contributor
Contributor

Esx5.5 attach detached lun via powercli

$esxcli.storage.core.device.set seems to have changed between esx5.1 and esx5.5 - all I need is a script to attach detached devices which are coming in as snapshot luns from a netapp device - does anyone have the new esx5.5 format?

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

Did you already see   Re: Modifying DNSRO on individual LUNs with PCLI - vSphere 5.5


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
js40687
Contributor
Contributor

I have been struggling with this also

the syntax changed between 5.0 and 5.1, went from 4 parms to 6 parms but always the last parm worked in single quotes as simply 'on' or 'off'

With 5.5 it seems to have moved to 8 parms, but it will not accept 'on' or 'off' as a parm

the post referred to above seemed to use $on, if I use $on or $off, I do not get an error, but it does not attach or detach the LUN. Do you need to setup $on or $off in advance? doesn;t seem to be a default variable

when I try the 'on' or 'off' as per 5.1 or 5.0 I get an error as per below

A specified parameter was not correct.

argumnent[2]

InnerText: argument[2]

At D:\Scripts\.......

+ $myesxcli.storage.core.device.set($true, $naa_lun, $null, $null, $null, $null, $ +++

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

the full command I run is

$myesxcli.storage.core.device.set($true, $naa_lun, $null, $null, $null, $null, $null, 'on')

I saw the 4th parm is Boolean, I have tried both $false and $true there with no success

I simply want to attach a LUN that is not attached and vice versa

Reply
0 Kudos
dokonek
Contributor
Contributor

I'm seeing the same exact problem with trying to detach with this syntax: $esxcli.storage.core.device.set($null,$CurrentLun,$null,$null,$null,$null,$null,'$off'). Error I get is

Message: A specified parameter was not correct.

argument[2];

InnerText: argument[2]

At line:1 char:1

+ $esxcli.storage.core.device.set($null,$CurrentLun,$null,$null,$null,$null,256,'$ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], InvalidArgument

    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidArgument

Reply
0 Kudos
SealEye
Contributor
Contributor

I too am having an issue getting the syntax to work.

It seems to fail on the device name argument no matter how I put it in, whether through a variable or entered directly as a string:

PowerCLI C:\scripts\storage> $esxcli.storage.core.device.set($null,"eui.00173800051b0625",$null,$null,$null,$null,$null,"off")

Message: A specified parameter was not correct.

argument[1];

InnerText: argument[1]

At line:1 char:32

+ $esxcli.storage.core.device.set <<<< ($null,"eui.00173800051b0625",$null,$null,$null,$null,$null,"off")

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : MethodInvocationException

Another example:

PowerCLI C:\scripts\storage> $devices = $esxcli.storage.core.device.list() | where {$_.Vendor -eq "IBM"} | Select -Expand Device

PowerCLI C:\scripts\storage> Foreach ($device in $devices){$esxcli.storage.core.device.set($null,$device,$null,$null,$null,$null,$null,"off")}

Message: A specified parameter was not correct.

argument[1];

InnerText: argument[1]

At line:1 char:62

+ Foreach ($device in $devices){$esxcli.storage.core.device.set <<<< ($null,$device,$null,$null,$null,$null,$null,"off")}

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : MethodInvocationException

Message: A specified parameter was not correct.

argument[1];

InnerText: argument[1]

At line:1 char:62

+ Foreach ($device in $devices){$esxcli.storage.core.device.set <<<< ($null,$device,$null,$null,$null,$null,$null,"off")}

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : MethodInvocationException

The $device variable is correct

I've tried skipping the variable and entering it directly, with single quotes, double quotes, no quotes... It never works.

I've looked at the other page mentioned above and used the exact same syntax to no avail.

I will note that on my 5.0 hosts the following syntax worked correctly:

$devices = $esxcli.storage.core.device.list() | where {$_.Vendor -eq "IBM"} | Select -Expand Device

Foreach ($device in $devices){$esxcli.storage.core.device.set($device,$null,$null,"off")}

But it does not work on my 5.5 hosts, this way or the other ways mentioned above.

If it matters, I am currently using PowerCLI 5.5 Release 2 Patch 1

If anyone finds the magic syntax, please post it.

Thanks!

Reply
0 Kudos
knikolov
VMware Employee
VMware Employee

I also tried the script proposed by LucD and it seems to work on my ESX 5.5. I just used to attach/detach luns like this:

$esxcli.storage.core.device.set($null, $cn, $null, $null, $null, $null, $null, "off")

I got the device name the same way as in the script listed there:

$luns = Get-VMHost 10.23.67.171 | Get-ScsiLun

$cn = $luns[1].CanonicalName

However this is with a default vmware disk.There might be some specifics with netapp disks.

Reply
0 Kudos
SealEye
Contributor
Contributor

So I figured it out and wanted to come back and share for anyone else that may experience the same issue.

Pretty simple to figure out in retrospect, but the fact that others were saying it was working for them with the 8 parameters as displayed is what kept throwing me off.

In my case it was in fact requiring 9 parameters.


This can be easily determined by entering the "set" command with no parameters...

PowerCLI C:\scripts\storage> $esxcli.storage.core.device.set()

...which gives you the following error:

The method 'set' is invoked with '0' parameters, but the expected parameter count is '9'.

At line:1 char:1

+ $esxcli.storage.core.device.set()

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], InvalidArgument

    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidArgument


It flat out tells you that the expected parameter count is '9'.

Repeating the command without the parenthesis shows you what those parameters are:

PowerCLI C:\scripts\storage> $esxcli.storage.core.device.set

TypeNameOfValue    : VMware.VimAutomation.ViCore.Util10Ps.EsxCliExtensionMethod

OverloadDefinitions : {void set(boolean defaultname, string device, boolean force, string name, boolean nopersist, long queuefullsamplesize, long

                      queuefullthreshold, long schednumreqoutstanding, string state)}

MemberType          : CodeMethod

Value              : void set(boolean defaultname, string device, boolean force, string name, boolean nopersist, long queuefullsamplesize, long

                      queuefullthreshold, long schednumreqoutstanding, string state)

Name                : set

IsInstance          : True


So long story short, the command that worked for me was:


Foreach($device in $devices){$esxcli.storage.core.device.set($null,$device,$null,$null,$null,$null,$null,$null,"off")}


Hope this helps...

Reply
0 Kudos