Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Created June 7, 2019 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loic-sharma/0ea9f02fd191e85ebc95ba5234e3581e to your computer and use it in GitHub Desktop.
Save loic-sharma/0ea9f02fd191e85ebc95ba5234e3581e to your computer and use it in GitHub Desktop.
azs-clean
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RootNamespace>AzsClean</RootNamespace>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Search" Version="9.0.1" />
</ItemGroup>
</Project>
using Microsoft.Azure.Search;
using Microsoft.Azure.Storage;
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
namespace azs_clean
{
public class Program
{
public static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}
public static async Task MainAsync(string[] args)
{
//# Storage Accounts
//az login
//$containers = az storage container list--account - name loshardev0--prefix "azs-"
//$names = $containers | ConvertFrom - Json | % { $_.Name }
//$names | % { az storage container delete --account - name loshardev0--name $_ }
// Delete all Azure Search indexes
var credentials = new SearchCredentials("SEARCH ADMIN KEY");
var client = new SearchServiceClient("SEARCH ACCOUNT NAME", credentials);
var listResult = await client.Indexes.ListAsync();
var indexNames = new ConcurrentBag<string>(listResult.Indexes.Select(i => i.Name));
var tasks = Enumerable
.Range(0, 32)
.Select(async i =>
{
await Task.Yield();
while (indexNames.TryTake(out var indexName))
{
Console.WriteLine($"Deleting Azure Search index {indexName}...");
await client.Indexes.DeleteAsync(indexName);
Console.WriteLine($"Deleted Azure Search index {indexName}");
}
})
.ToList();
await Task.WhenAll(tasks);
Console.WriteLine("Done");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment