We have a process where we input a list of approx 15 disk devices into a foreach loop to add them to a VM (see code snippet). The process works fine, however there's an approximately 1 minute delay between each actual device mapping as when viewed from the "Recent tasks" view in the client... Any ideas on what could be causing this delay between mappings and/or ways to speed it up?... thx...
If you use a column header try something like this
Import-Csv C:\names.csv -UseCulture | %{"naa." + $_.DeviceId}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The 1st improvement I can think of is to replace the 15 calls to Get-ScsiLun by 1 call.
This can be done by using a hashtab, something like this
$lunTab = @{} Get-ScsiLun -VmHost $esxhost -LunType disk | %{ $lunTab.Add($_.CanonicalName,$_.ConsoleDeviceName) } # Add RDM Disks foreach ($rdmID in $rdmIDs){ Write-host "Mapping" $rdmID.DeviceId "as a replay volume to" $vmName
$deviceName = $lunTab[$rdmID.DeviceID] New-HardDisk -VM $vmName -DiskType RawPhysical -DeviceName $deviceName | Out-Null
}
# End adding RDM Disks
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
For some reason it's not taking the 'DeviceName' variable - getting the following error:
New-HardDisk : Cannot validate argument on parameter 'DeviceName'. The argument is null. Supply a non-null argument and try the command again.
+ New-HardDisk -VM $vmname -DiskType RawPhysical -DeviceName <<<< $deviceName | Out-Null
+ CategoryInfo : InvalidData: (:) [New-HardDisk], ParameterBindingValidationException
+ FullyQualifiedErrorID : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk
any ideas?
I assumed you have CanonicalNames in the array $rdmIDs, is that correct ?
Do all the strings in $rdmIds appear in
Get-ScsiLun -vmhost $esxhost -LunType disk | Select CanonicalName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD - I got it working.. The rdmID was lacking the "naa" - once added worked like a champ.. BTW - been eying your book on Amazon, looking forward to reading it..
Running into one more small hitch - we are sourcing an existing .csv file for the device names, in the format of:
6000d3100030890000000000000001d9 | |||
6000d3100030890000000000000001da | |||
6000d3100030890000000000000001db |
We run import-csv to populate the $rdmIDs variable.. What I would like to do during the import is to pre-pend "naa." to each record - so as to end up with complete CanonicalNames, i.e. : naa.6000d3100030890....... If possible would like to do this without creating another .csv, instead injecting the "naa." directly into each $rdmIDs record as it's populated via the import-csv process.. Is this even possible?
Try something like
Import-Csv C:\names.csv -UseCulture | %{"naa." + $_}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Almost there - it's adding "naa." along with some unwanted additions:
Import-Csv C:\deviceid.csv -UseCulture |%{"naa." + $_}
Result: naa.@{DeviceId=6000d3100030890000000000000001d9}
Target: naa.6000d3100030890000000000000001d9
To make it clearer - the reason it added "DeviceId" is it's contained in the source .csv file - The complete source file is actually:
DeviceId
6000d3100030890000000000000001d9
6000d3100030890000000000000001da
6000d3100030890000000000000001db
If you use a column header try something like this
Import-Csv C:\names.csv -UseCulture | %{"naa." + $_.DeviceId}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That was it...... just what I was looking for..... appreciate it....
Running into one more hitch with this set up.. When pre-pending the "naa.", it appears to lose its formatting, so when the array is fed into looping statements, it doesn't recognize it's the last record.. By default, import-csv will return a blank/new line in the output: e.g.
$RDMid
DeviceID
----------
naa.60000d31........
naa.60000d31........
naa.60000d31........
PS >
However when "naa." is prepended, the output appears as:
$RDMid
naa.60000d31........
naa.60000d31........
naa.60000d31........
PS >
Is there a way to add this line feed/carraige return to the end of the array? thx....
That's because that small script didn't produce objects but just an array of strings.
If you want the output to look similar to the Import-Csv you can do
Import-Csv C:\names.csv -UseCulture | %{New-Object PSObject -Property @{DeviceId = "naa." + $_.DeviceId}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Worked! As always --- appreciate it LucD.........