Hi All,
I am struggling with wrapping my head around Windows PowerShell.  the inner nerd inside of my head wants to be a masterful script creator using windows powershell, however whenever i try to write scripts i find myself getting lost in the syntax and not creating anything that even remotely works.
Thankfully the ISE does help me by providing hints about what the strings are for each cmdlet, but what it doesn't help me with is the logic behind building scripts that do multiple things and/or trigger a cmdlet based on a set of criteria being met.  for example, something really simple: Deleting all hyper-v VM's in windows 10, i like to call this the "lab squashing script".
I have found numerous scripts online that do the trick just fine with individual VM's, which i have been re-purposing for my needs.  However i am challenging myself to create my own script that achieves the same thing and once done will be comparing the code to see how efficient or inefficient it is.
The script i have compiled that does not work as intended is as follows:
Get-VM -Name * | Stop-VM | Remove-VMSnapShot | Remove-VMHardDiskDrive | Remove-VM -Name *
the goals are:
1) Retrieve the names of all Guest VM's installed
2) pipe this data into a cmdlet to shutdown all running VM's such as stop-vm
3) Next i would like to remove any snapshots for the VM's
4) Then i would like to delete all vhdx files associated with a VM, this is where i start to struggle.  I have found remove-vmharddisk but that doesnt work the way i want it to.
5) Lastly, i would like to delete the guest VM object from the Hyper-V manager.
To be clear, i am not looking for someone to write a script for me, i would much prefer some pointers on how to go about learning the nature of the language and how to put together scripts that are more complex than "1 liners"Thanks in advance