LucD
I don't have csv but I have something like below. It's not working. Any idea how do I construct the forEach loop here? How do I construct the correct $device below? Thanks in advance!
$deviceName = (Get-VMHost | Get-ScsiLun | Where {$_.CapacityGB -match "10"}).ConsoleDeviceName
foreach ($item in $deviceName){
$device = $item
New-HardDisk -VM win2k12r2_srv2 -DiskType RawPhysical -DeviceName $device
}
Error I am getting:
New-HardDisk : Cannot validate argument on parameter 'DeviceName'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At line:3 char:71
+ ... HardDisk -VM win2k12r2_srv2 -DiskType RawPhysical -DeviceName $device
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-HardDisk], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk
New-HardDisk : Cannot validate argument on parameter 'DeviceName'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At line:3 char:71
+ ... HardDisk -VM win2k12r2_srv2 -DiskType RawPhysical -DeviceName $device
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-HardDisk], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk