title: Automation to delete unused VMs and their resources in Azure by last power on date
body: <p>I need to create an automation that will delete VMs that were not started in the last two weeks and their associated resources (for example a Network interface or a Disk etc..) inside a single resource group. I thought about using a Powershell runbook in an automation account but I have some problems with that, I couldn't find a Powershell command to check last start date of all VMs in a resource group or a Powershell command to delete a VM and all its' associated resources.
  If I had these two I could make a Powershell runbook that will check last start time of a VM and if the date exceeds two weeks it'd automatically delete it and its' associated resources.
  Anyone knows how to accomplish these two things or maybe knows a different way to do this?</p>