Example #1
0
        private static async Task DeleteUser(string username)
        {
            if (IsNotAdminUserName(username))
            {
                //await RemoveTryAppResource(username);
                dynamic GraphClient;
                GraphClient =
                    await
                    ARMLib.GetDynamicClient(apiVersion : "1.42-previewInternal",
                                            url : string.Format("{0}/{1}", "https://graph.windows.net", SimpleSettings.TryTenantId))
                    .ConfigureLogin(LoginType.Upn, SimpleSettings.TryUserName, SimpleSettings.TryPassword);

                var users = (GraphArray)await GraphClient.Users.Query("$top=999").GetAsync <GraphArray>();

                foreach (var user in users.value)
                {
                    if (user.acceptedOn != null &&
                        new[] { username }.All(
                            n => user.displayName.IndexOf(n, StringComparison.OrdinalIgnoreCase) > -1))
                    {
                        console(
                            $"Found and deleting:{user.displayName} from tenant:{SimpleSettings.TryTenantId}");
                        await GraphClient.Users[user.objectId].DeleteAsync();
                        return;
                    }
                }
            }
            else
            {
                console($"Admin Username:{username} . Cannot be deleted");
            }
        }
Example #2
0
        static async Task Run()
        {
            dynamic GraphClient;

            GraphClient = await ARMLib.GetDynamicClient(apiVersion : "1.42-previewInternal", url : string.Format("{0}/{1}", "https://graph.windows.net", SimpleSettings.TryTenantId))
                          .ConfigureLogin(LoginType.Upn, SimpleSettings.TryUserName, SimpleSettings.TryPassword);

            var tasks = new List <Task>();

            while (true)
            {
                var users = (GraphArray)await GraphClient.Users.Query("$top=999").GetAsync <GraphArray>();

                foreach (var user in users.value)
                {
                    if (user.acceptedOn != null &&
                        user.acceptedOn < DateTime.UtcNow.AddDays(-2) &&
                        new[] { "ahmels", "graphAdmin", "trywebsitesnow" }.All(n => user.displayName.IndexOf(n, StringComparison.OrdinalIgnoreCase) == -1))
                    {
                        Console.WriteLine(user.displayName);
                        tasks.Add(GraphClient.Users[user.objectId].DeleteAsync());
                    }

                    if (tasks.Count >= 50)
                    {
                        await Task.WhenAll(tasks);

                        tasks.Clear();
                    }
                }
            }
        }
Example #3
0
        private static async Task Run()
        {
            var armClient = ARMLib.GetDynamicClient(apiVersion: "2014-11-01").ConfigureLogin(LoginType.Upn, "userName", "password");

            var resrouceGroups = await armClient.Subscriptions["{subscriptionId}"]
                                 .ResourceGroups
                                 .GetAsync <JObject>();

            foreach (var resrouceGroup in resrouceGroups.value)
            {
                var sites = (Site[])await armClient.Subscriptions["{subscriptionId}"]
                            .ResourceGroups[resrouceGroup.name]
                            .Providers["Microsoft.Web"]
                            .Sites
                            .GetAsync <Site[]>();

                if (sites.Length == 0)
                {
                }
            }
        }
Example #4
0
        static async Task Run()
        {
            dynamic GraphClient;

            GraphClient = await ARMLib.GetDynamicClient(apiVersion : "1.42-previewInternal", url : string.Format("{0}/{1}", "https://graph.windows.net", SimpleSettings.TryTenantId))
                          .ConfigureLogin(LoginType.Upn, SimpleSettings.GraphUserName, SimpleSettings.GraphPassword);

            var tasks = new List <Task>();

            while (true)
            {
                var users = (GraphArray)await GraphClient.Users.Query("$top=999").GetAsync <GraphArray>();

                var usersToDelete = users.value.Where(user => user.acceptedOn != null && user.acceptedOn < DateTime.UtcNow.AddHours(-4) && IsNotAdminUserName(user.displayName)).ToList();
                if (!usersToDelete.Any())
                {
                    if (tasks.Any())
                    {
                        await Task.WhenAll(tasks);
                    }
                    return;
                }
                else
                {
                    foreach (var user in usersToDelete)
                    {
                        Console.WriteLine(user.objectId);
                        tasks.Add(GraphClient.Users[user.objectId].DeleteAsync());

                        if (tasks.Count >= 50)
                        {
                            await Task.WhenAll(tasks);

                            tasks.Clear();
                        }
                    }
                }
            }
        }