Created
June 7, 2019 23:18
-
-
Save loic-sharma/0ea9f02fd191e85ebc95ba5234e3581e to your computer and use it in GitHub Desktop.
azs-clean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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