jrudlin/Azure

Storage account name becomes too long

Closed this issue · 3 comments

I suggest changing 39 line in https://github.com/jrudlin/Azure/blob/master/General/Shrink-AzDisk.ps1
$storageAccountName = "sashrinkddisk" + ($($VMName -replace '[^a-zA-Z0-9]', '')).ToLower()
to
$storageAccountName = "shrink" + [system.guid]::NewGuid().tostring().replace('-','').substring(1,18)
to account for errors like "....is not a valid storage account name. Storage account name must be
between 3 and 24 characters in length and use numbers and lower-case letters only."

Great point @SvenSowa , how about we compromise on this:

"sashrinkddisk" + ($($VMName -replace '[^a-zA-Z0-9]', '')).ToLower().substring(0,11)

😃

Sure thing. That will work too, as long as its globally unique. I also have more suggestions for your great script.
Line 1:
param($AzSubscription,$VMName,$DiskSizeGB = 32)

$DiskID should move to after line 19
$vm.StorageProfile.OsDisk.ManagedDisk.Id
$DiskID = $vm.StorageProfile.OsDisk.ManagedDisk.Id

and further below I would copy the disk SKU from the old disk
$accountType = $disk.Sku.Name # was "Premium_LRS".

Update-AzVM at the end of the script failed for me once with a strange error "Managed disk resize via Virtual Machine 'xyz' is not allowed. Please resize disk resource at....". Strangely rerunning the command worked then.

Good call thanks @SvenSowa . I've incorporated that except the params and DiskID change, as I wanted to keep it open for us with other disks that maybe attached to the VM and not assume it is the OS disk. It would of course need a few more updates to get to that stage though.