Skip navigation
VMware

This Question is Answered (go to answer)

3,567 Views 32 Replies Last post: Mar 18, 2009 12:02 AM by RobMokkink RSS
1 2 3 Previous Next
RobMokkink Expert 811 posts since
Jun 7, 2005
Currently Being Moderated

Jul 14, 2008 10:58 PM

storage-path script

 

Yes another question.

I am busy creating a script according to the sniplet examples on the blog, here is the code:

 

 

 

 

 

#VARIABLES

$policy = new-object VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy

$policy.policy = "fixed"

 

 

 

 

 

$ESXHOST = read-host -prompt "Enter Host"

$USER = read-host -prompt "Enter User"

$PASSWORD_PROMPT = read-host -assecurestring -prompt "Enter password"

 

 

 

 

 

#CONVERT THE SECURE STRING

$CONVERT_PASSWORD = http://System.Runtime.InteropServices.Marshal::SecureStringToBSTR($PASSWORD_PROMPT)

$PASSWORD = http://System.Runtime.InteropServices.Marshal::PtrToStringAuto($CONVERT_PASSWORD)

 

 

 

#CONNECT TO THE SERVER

Get-esx -Server $ESXHOST -User $USER -Password $PASSWORD | fl

 

 

#GET THE STORAGE PATHS

$GET_HOST = Get-VMhost $ESXHOST

$HOST_VIEW = Get-View $GET_HOST.id

$STORAGESYSTEM = get-view $HOST_VIEW.ConfigManager.StorageSystem

 

 

#MAKE THE PATH FOR EACH LUN FIXED

write-output "SET LUN PATHS TO FIXED"

 

 

$STORAGESYSTEM.StorageDeviceInfo.MultipathInfo.lun | where { $_.Path.length -gt 1 } | foreach { $STORAGESYSTEM.SetMultipathLunPolicy($_.ID, $policy) }

 

 

 

 

 

When running the script i get errors:

 

 

New-Object : Cannot find type [VMware.Vim.HostMultipathInfoFixedLogicalUnitPoli

cy]: make sure the assembly containing this type is loaded.

At F:\Powershell\set-storagepaths.ps1:6 char:21

+ $policy = new-object  <<<< VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy

Property 'policy' cannot be found on this object; make sure it exists and is se

ttable.

At F:\Powershell\set-storagepaths.ps1:7 char:9

+ $policy.p <<<< olicy = "fixed"

 

 

It looks like the object is not supported.

 

 

What am i doing wrong?

 

 

LucD Guru User Moderators vExpert 8,994 posts since
Oct 31, 2005
Currently Being Moderated
2. Jul 15, 2008 12:32 AM in response to: RobMokkink
Re: storage-path script

To get the LUN Id into a variable you could use something like this

 

$LunId = $STORAGESYSTEM.StorageDeviceInfo.MultipathInfo.lun | where { $_.Path.length -gt 1 } | select ID

 

Better yet, make a new object and store all the properties you want to pass.

 

$LUNInfo = "" | select ID, Path
$STORAGESYSTEM.StorageDeviceInfo.MultipathInfo.lun | where { $_.Path.length -gt 1 } | %{$LUNInfo.ID = $_.ID; $LUNInfo.Path=$_.Path}

 

To test for even/uneven you can use a binary and with 1 on the LUN Id.

 

Something like this

 

if($LUNId -band 1) {Write-Host "Uneven"}
else {Write-Host "Even"}

 

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
LucD Guru User Moderators vExpert 8,994 posts since
Oct 31, 2005
Currently Being Moderated
6. Jul 15, 2008 2:29 AM in response to: RobMokkink
Re: storage-path script

You can force a load of the assembly in the beginning of your script.

 

[http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("vmware.vim")

 

I attached a file with this line since the forum SW tends to reformat certain characters.

Attachments:
Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
LucD Guru User Moderators vExpert 8,994 posts since
Oct 31, 2005
Currently Being Moderated
8. Jul 15, 2008 3:06 AM in response to: RobMokkink
Re: storage-path script

You need to pass some parameters to the PowerShell command.

See  Connecting to the vitoolkit from a commandline and also  VI Toolkit (for Windows) Admin Guide

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
CITITECHS Enthusiast 41 posts since
Feb 4, 2008
Currently Being Moderated
12. Jul 23, 2008 4:07 PM in response to: RobMokkink
Re: storage-path script

Great Script

LucD Guru User Moderators vExpert 8,994 posts since
Oct 31, 2005
Currently Being Moderated
14. Jul 24, 2008 12:37 AM in response to: RobMokkink
Re: storage-path script

Not from where I'm sitting

Had to reply via email.

Since yesterday morning I haven't seen recent content.

The most recent entries are more than 1 day old.

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com

Bookmarked By (0)

Share This Page

Communities