Yes I' m just using the example 6 but I have to use a variable so my script:
$PVID = "1234"
$Myhost = "HOSTRM$PVID.lab.it"
$MyVM = "VM$PVID"+"RM"
$pathdisk = "[/datastore1\ -\ lab$PVID] /Repository/VMDK/newdisk.vmdk"
New-HardDisk -VM $MyVM -DiskPath $pathdisk
I receive the following errors:
New-HardDisk : 25/11/2019 16:01:56 New-HardDisk No matching datastore found.
At line:1 char:1
+ New-HardDisk -VM "VM1234RM" -DiskPath $dspath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [New-HardDisk], VimException
+ FullyQualifiedErrorId : Client20_VirtualDeviceServiceImpl_NewVirtualHardDisk_DatastoreNotFound,VMware.VimAutomation.Vi
Core.Cmdlets.Commands.VirtualDevice.NewHardDisk
If I will use your script syntax all works fine
Get-VM -Name $MyVM | Get-HardDisk | Select @{N='VM';E={$_.Parent.Name}},Name,FileName | Export-Csv -Path .\disknames.csv -UseCulture -NoTypeInformation
Before import I modify the csv file as follow:
"VM";"Name";"Filename"
"VM9992RM";"Hard disk 2";"[datastore1 - lab1234] Repository/VMDK/newdisk.vmdk"
$importcsv = Import-Csv -Path .\disknames.csv -UseCulture
$newFileName = $importcsv.FileName
New-HardDisk -VM "MyVM" -$importcsv.FileName
Regards