r/PowerShell • • Jun 16 '17

Why PowerShell is so complicated?

Ok, this is how do you attache a disk to VM on Azure (according to Azure documentation).

$diskConfig = New-AzureRmDiskConfig -Location EastUS -CreateOption Empty -DiskSizeGB 128 $dataDisk = New-AzureRmDisk -ResourceGroupName myResourceGroup -DiskName myDataDisk -Disk $diskConfig $vm = Get-AzureRmVM -ResourceGroupName myResourceGroup -Name myVM $vm = Add-AzureRmVMDataDisk -VM $vm -Name myDataDisk -CreateOption Attach -ManagedDiskId $dataDisk.Id -Lun 1 Update-AzureRmVM -ResourceGroupName myResourceGroup -VM $vm

Why is this should be five lines? Can't it be simple? For example:

New-AzureRMVMDisk -VM nameofthevm -diskname nameofthedisk -type typeofthedisk etc.

I mean why PowerShell complicates things? After all it is command line tool that should make our life little bit easier.

1 Upvotes

10 comments sorted by

View all comments

3

u/midnightFreddie Jun 16 '17

Generally speaking, GUIs are easier for one-off tasks. That's why they're so damn popular.

If you need to add a new blank disk to each of 150 existing VMs and for each new VM created, scripting blows away any GUI.

But even "one-off" situations aren't often one-off; maybe you need to add a disk a couple of times a month or week, and you can parameterize the script...well you basically make your own function that takes the arguments you wish for in OP, and boom you got your easy mx item.

Powershell cmdlets do focused, basic things each, and you string them together. Lots of scripting languages are like that. Your need for adding a disk is different from mine, and they can't anticipate all needs, so you have building blocks.