Skip to content

Instantly share code, notes, and snippets.

@frankhu-2021
Created November 4, 2018 03:10
Show Gist options
  • Save frankhu-2021/c304c39aa4415f99d8c663bb3ed529c3 to your computer and use it in GitHub Desktop.
Save frankhu-2021/c304c39aa4415f99d8c663bb3ed529c3 to your computer and use it in GitHub Desktop.
This method will create users for a test tenant in order to test paging, or if you're trying to do some sort of testing.
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System.Net.Http.Headers;
using System.Net.Http;
static async Task createRandomUsers()
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
Console.WriteLine("\n \n Creating users {0}", DateTime.Now.ToString());
for(int index = 0;index < 10; ++index)
{
var values = "{\r\n \"accountEnabled\": true,\r\n \"displayName\": \"TestName "+ index + "\",\r\n \"mailNickname\": \"TestNameNickName\",\r\n \"userPrincipalName\": \"TestNameNickName"+index+"@" + tenantID + "\",\r\n \"passwordProfile\" : {\r\n \"forceChangePasswordNextSignIn\": true,\r\n \"password\": \"MyNewPassword123\"\r\n }\r\n}";
var content = new StringContent(values, Encoding.Default, "application/json");
HttpResponseMessage response = await httpClient.PostAsync(resourceUri + "/v1.0/users", content);
if (response.IsSuccessStatusCode)
{
// Read the response and output it to the console.
string users = await response.Content.ReadAsStringAsync();
JavaScriptSerializer serializer = new JavaScriptSerializer();
Console.WriteLine("\n \n Printing Created User \n \n");
Console.WriteLine(JsonPrettify(users));
Console.WriteLine("Received Info");
}
else
{
Console.WriteLine("Failed to retrieve To Do list\nError: {0}\n", response.ReasonPhrase);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment