Azure - Identify and Optionally Delete Orphaned Disks

PowerShell script to automate identifying "Orphaned Disks" in an Azure subscription. An Orphaned Disk is a Disk that does NOT have an "Active Lease" (Unmanaged Disks) or does NOT have a "ManagedBy" property set to a VM (Managed Disks). The script outputs information to a log fil

 
 
 
 
 
5 Star
(2)
3,989 times
Add to favorites
Windows Azure
5/15/2019
E-mail Twitter del.icio.us Digg Facebook
  • Export the script result into CSV
    3 Posts | Last post March 19, 2019
    • Hi Neil,
      
      I have used this script, and it works absolutely fine. However, I want the script output tobe get exported into a .csv file. Also, I would like to know whether we can export the file to storage account directly. Currently Set-AzureStorageBlobContent -File "$FileName" -Container hellotest -Blob Savedfile.csv
    • Hi Satish, in relation to your question above:
      
      The script already exports the results into .CSV files, you should find 2 x files: "azure-orphaned-Managed-disks.csv" and "azure-orphaned-Managed-disks.csv", these will be created in the directory the script is executed from by default, or you can pass an Output directory using the "-OutputFolderPath" parameter when calling the script.
      
      As for outputting directly to an Azure Storage Account, this is possible but this was not required / in scope for this version of the Orphaned Disk script. You could upload the results to a Storage account using a separate script if you wish. 
      
      Hope this helps.
      Regards
      Neil
    • Hello Neil,
      
      This script works very well when you run and store the result in local machine. I want to use this script with automation account and run every month or week through a runbook. So please see if you can make necessary changes to use this script with automation account.
  • Powershell to list & delete Azure Orphaned NICs, IP Address, NSGs
    1 Posts | Last post March 05, 2019
    • Hello Nail,
      
      can we have such PS script to list & delete Azure orphaned NICs, IP Address, NSGs also.
  • Azure Automation Account.
    1 Posts | Last post November 08, 2018
    • Hello Nail, this is a great script, it is perfectly working, thanks a lot for it.
      
      I hope you can help us with some difficulties that we are having when we try to set it inside an automation account in Azure.
      
      It is possible to configure it inside Azure to export that csv and send it to an email?
      
      I have the connection string to automate gate the subscription info and also the send email script.
      
      But when we run it, we received the following error, and I don't know what to configure in your script to bypass it or avoid the out grid for subscription selection. 
      
      Failed
      At line:60 char:1
      + [CmdletBinding()]
      + ~~~~~~~~~~~~~~~~~
      Unexpected attribute 'CmdletBinding'.
      
      At line:61 char:1
      + Param(
      + ~~~~~
      Unexpected token 'Param' in expression or statement.
      
      At line:692 char:38
      + Write-Output "Email sent succesfully."
      +                                      ~
      The string is missing the terminator: ".
      
      At line:64 char:34
      +         [string]$SubscriptionName = "SUBSCRIPTION NAME",
      +                                     ~~~~~~~~~~~~~~~~~~~
      The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments, such as a variable or a property.
      
      
      Thanks, best regards.