VMware Cloud Community
bleksons
Contributor
Contributor

adding new disk using powercli with env variable for disk size

Hello 

 

Anybody can share a suggestion on how to specify a new disk with powercli where it will prompt you for disk size in GB? 

So far I can use this simple script for predefined value for adding disk to be used with clustered nodes but want to build it for dev folks so they can specify this themselves 

$vm = Get-VM VMNAME  

$vm | New-Harddisk -CapacityGB 100 -StorageFormat EagerZeroedThick -Controller "SCSI Controller 1" -Persistence IndependentPersistent

Reply
0 Kudos
11 Replies
LucD
Leadership
Leadership

You mean a prompt on screen?
Or by getting the value from an environment variable?

Btw, the value on CapacityGB should be just 100, not 100GB.
Otherwise, you're assigning a disk of 100GB * 1GB.


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

Reply
0 Kudos
bleksons
Contributor
Contributor

yes , prompt on the screen

sorry I do have it set to 100 for the test 

Reply
0 Kudos
LucD
Leadership
Leadership

You could use a simple Read-Host

$vm = Get-VM VMNAME  
$size = Read-Host -Prompt "Enter size of the disk (in GB)"
$vm | New-Harddisk -CapacityGB $size -StorageFormat EagerZeroedThick -Controller "SCSI Controller 1" -Persistence IndependentPersistent


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

Reply
0 Kudos
bleksons
Contributor
Contributor

thank you so much that worked ! i'm not much of the scripter 

I also tried to see if I can specify the vmdk name to make this easier for adding an existing disk to the second node ( so I can just reference it without checking) but I do not see a parameter for this in powercli , do you happen to know if this is not possible? 

Reply
0 Kudos
LucD
Leadership
Leadership

You can use the DiskPath parameter on the New-Harddisk cmdlet.


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

Reply
0 Kudos
bleksons
Contributor
Contributor

Ok tried running that, is this the correct format? or do I need to have datastore in the path? I'm referencing it already in the script but not in the path

$VMName = Read-Host -Prompt "Enter VM Name"
$vm = Get-VM $VMName
$size = Read-Host -Prompt "Enter size of the disk (in GB)"
$diskpath = Read-Host -Prompt "Provide disk path as VMName/VMName_disknumber.vmdk as VMNAME/VMNAME_5.vmdk"

$vm | New-Harddisk -CapacityGB $size -Datastore snap-37ecf0ed-SQLCLSDRTEST -DiskPath $diskpath -StorageFormat EagerZeroedThick -Controller "SCSI Controller 1" -Persistence IndependentPersistent

here is my error message 

Provide disk path as VMName/VMName_disknumber.vmdk as VMNAME/VMNAME_5.vmdk: HTVP-DRCLS-N1/HTVP-DRCLS-N1_6.vmdk
New-HardDisk : Parameter set cannot be resolved using the specified named parameters.
At C:\temp\newdisk.ps1:6 char:7
+ $vm | New-Harddisk -CapacityGB $size -Datastore snap-37ecf0ed-SQLCLSD ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-HardDisk], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk

 

 

Reply
0 Kudos
LucD
Leadership
Leadership

When you are using the DiskPath parameter some of the other parameters can not be used.
In PowerShell this is called parametersets of cmdlets.
The link I posted earlier shows which other parameters you can use together with DiskPath.

diskpath.jpg


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

Reply
0 Kudos
bleksons
Contributor
Contributor

so this parameter can only be used for the existing disk, not when creating new vmdk, ok I see now, thank you for all the info on this 

Reply
0 Kudos
bleksons
Contributor
Contributor

hate to bug more on this but when it comes to adding an existing disk to my second SQL node , is there a way to parameterize vmdk disk to prompt for entry?

For example here is the file name of the disk I want to add: [test] VMNAME-N1/VMNAME-N1_6.vmdk 

I can parameterize first piece of it where [test] $vm1

$vm1 = Read-Host -Prompt "Enter First node Server Name"

but having trouble doing that for what comes after "/" sign which is: VMNAME-N1_6.vmdk 

keep getting "file [test] VMNAME-N1/ was not found 

 

Please advise  

Reply
0 Kudos
LucD
Leadership
Leadership

I would need to see the code you are using


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

Reply
0 Kudos
bleksons
Contributor
Contributor

actually, I think I got it using the whole portion of the patch as a variable, for this activity my datastore will always be the same. 

$VMName = Read-Host -Prompt "Enter VM Name"
$vm = Get-VM $VMName
$vm1path = Read-Host -Prompt "Enter First node Server Name and disk path as VMNAME-N1/VMNAME-N1_6.vmdk"
$vm | New-Harddisk -DiskPath "[TEST] $vm1path" -Controller "SCSI Controller 1" -Persistence IndependentPersistent

 

Still, thank you for all the previous replies! 

Reply
0 Kudos