VMware Cloud Community
markc2000
Contributor
Contributor

New-HardDisk acting very strange when trying to add a disk to a VM

I'm beating my head against a wall on this issue. I've been trying everything to get this to work.

I'm using a Nimble to create a cloned volume by doing this:

$dbVol1 = New-NSVolume -Name "Clone-$($dbsnap1[0].vol_name)-$YYYYMMDD" -clone 1 -base_snap_id $dbsnap1[0].id

Then, later in the script, I'm removing the original disk from the VM, and trying to add the same VMDK from the cloned volume, by doing this:

New-HardDisk -DiskPath "$($dbVol1) $($dbhd2new[1])" -VM $DBServer -Persistence "Persistent"

If I print the variables about, I get:

PS C:\> Write-Host "[$($dbVol1.Name)] $($dbhd2new[1])"
[DSName-2021-08-17] ServerName/ServerName_7.vmdk

The above looks to be correct for what New-HardDisk is looking for, but when I attempt to run it, I get the following:

PS C:\> New-HardDisk -DiskPath "[$($dbVol1.Name)] $($dbhd2new[1])" -VM $DBServer -Persistence "Persistent"
New-HardDisk : 8/17/2021 11:51:35 AM New-HardDisk File [DSName-2021-08-17] ServerName/ was not found
At line:1 char:1
+ New-HardDisk -DiskPath "[$($dbVol1.Name)] $($dbhd2new[1])" -VM $DBSer ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-HardDisk], FileNotFound
+ FullyQualifiedErrorId : Client20_DatastoreServiceImpl_ExecuteDatastoreSearch_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk

It's removing everything after the / and I have no idea why.

If I add the disk from the GUI, it works fine.

 

EDIT: I figured out the issue, since I'm adding a cloned drive from Production, the folder names and the VMDK files are named after the Production server, not the test server, so my path was in fact incorrect. Now I need to find out how I can grab the path to the correct files.

0 Kudos
3 Replies
LucD
Leadership
Leadership

I don't immediately see why this fails.

You can check in the vpxd log on the VCSA, look for a ReconfigVM call around the time you launched the New-Harddisk cmdlet.
It most of the time provides more info on the issue


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

0 Kudos
markc2000
Contributor
Contributor

I realized what I did. To understand, I need a little bit of backstory... Every week, we "refresh" our development environment by taking a clone of Production from our Nimble and attaching some of the data drives to the development servers.

When I was trying to add the disks, I was using the correct Datastore, but I was incorrectly using the Development server name as the folder, and underlying name of the VMDK, which obviously named different because it was coming from Production.

Now I need to figure out a good way to build that string in the script so I can pass the correct path and filename, which may just be to hard code it, since I'm trying not to over think this.

Thoughts?

TIA

0 Kudos
LucD
Leadership
Leadership

If a fixed part of the filepath is different, you could use the Replace method, available on any string, to adapt the name.

If the replacement is more complex, you can use the -Replace operator, which accepts RegEx.


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

0 Kudos