I am writing a powershell/powercli script to automate adding RDM disks to two VM's in a two node Windows Failover Cluster for SQL.
The RDM disks are presented from a physical storage unit and using their naa.id's I can successfully add them to my first VM without issue using the New-HardDisk module like shown below (thanks lucd for earlier help):
$DataStore = "DataStore_Name_RDM"
$VM1 = Get-VM -Name "VM1"
$VM2 = Get-VM -Name "VM2"
The Select-Object cmdlet doesn't return a single String, but an object.
The DiskPath expects a String.
Try with
$DiskPath = ((Get-VM -Name $Server1 | Get-HardDisk | Where-Object {$_.Filename -Match "_RDM"}).FileName)[1]
Note: assuming that the 2nd returned String , with [1], is the correct HD might be risky.
Better is to match part of the value in the FileName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the reply.
I tried it with:
$DiskPath = ((Get-VM -Name $Server1 | Get-HardDisk | Where-Object {$_.Filename -Match "_RDM"}).FileName)[1]No luck, same error still unfortunately.
For now using [1] is ok but in my full code for the automation I have an index that increments with every loop.
Did you check what you have in $DiskPath and the type?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes I did, sorry I should have put the results.
Type
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
And the output was as expected.
And how did you do the New-HardDisk?
Because that should now be
New-HardDisk -VM $VM2 -DiskPath $DiskPath | New-ScsiController -Type ParaVirtual -BusSharingMode Physical
No FilePath property
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yep the New-HardDisk command was exactly as you pasted, without the .FileName extension:
Then I'm out of ideas I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sad times :(.
I will keep looking and feedback here if I find anything!
With a bit more investigation I have found that this is nothing to do with the code. It looks to be down to some specific datastores in our vCenter as I have my script working on a different datastore, using the methods discussed here + some.
No idea what the cause is on the datastore, but we are looking further.
If you have any suggestions, please fire away!
Hi again,
So far I've now found this difference.
When running:
You could try to unregister/register that VM, and check if that changes the type of the files.
Do all VMs on that datastore show the VMDK as "file"?
I suggest opening an SR.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I normally create new scsi controller first on second node with flat disk, then get scsi name
Then, get disk naa id from node 1 and export result to csv
Thanks for the suggestion JieX, I already have the naa.id for the disk and the issue isn't creating the SCSI controller.
Considering the code works 100% on Datastores with a version of 6.81, its got to be something related to the versioning and the file type.
We will be raising a SR soon once I get relevant access from the company I work for.
