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/fourierswager Jun 16 '17

Well, a lot of folks would say that is simpler and more flexible than one function with 20 different parameters.

The philosophy behind this basically says that creating small functions that do one thing makes it easier to diagnose issues/bugs when they are all combined into a larger script.

Then you might say:

"Well, the one thing I want to do is create a new VM."

Okay, but is that literally the ONLY scenario in which defining a Disk Configuration would be useful? What if you want to add a new disk to an existing VM? This is why defining the Disk Configuration is its own cmdlet. Extend this philosophy to all scenarios in Azure, and you end up with 100s of cmdlets that do very specific things (which, again, is a good thing according to this philosophy, and I'd tend to agree).

If you want to make Azure VM deployment simpler/maintainable, then I agree with /u/belstarr - use templates and write a function that digests those templates. That being said, there are products out there that do this already, like Terraform. (There's a learning curve, but once you learn it, you can create deployments that are Cloud Provider agnostic).