Sie können die Microsoft Graph-API verwenden - Create User:
eine Native Client App auf Azure AD registrieren, weisen Sie das "Microsoft Graph"> "Lesen und Schreiben von Verzeichnisdaten" Erlaubnis.

string authority = "https://login.windows.net/yourdomain.onmicrosoft.com";
string clientId = "{app_client_id}";
Uri redirectUri = new Uri("http://localhost");
string resourceUrl = "https://graph.microsoft.com";
HttpClient client = new HttpClient();
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resourceUrl,
clientId, redirectUri, PromptBehavior.Always);
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + authenticationResult.AccessToken);
string content = @"{
'accountEnabled': true,
'displayName': 'testuser',
'mailNickname': 'test',
'passwordProfile': {
'forceChangePasswordNextSignIn': true,
'password': '[email protected]'
},
'userPrincipalName': '[email protected]'
}";
var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");
var response = client.PostAsync("https://graph.microsoft.com/v1.0/users", httpContent).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
Eine nicht behandelte Ausnahme des Typs ‚System.FormatException‘ aufgetreten in Microsoft.IdentityModel.Clients.ActiveDirectory.dll – bijupranavam
Zusätzliche Informationen: Index (Null-basiert) muss größer als oder gleich Null ist und weniger als die Größe der Argumentliste. – bijupranavam
Stellen Sie sicher, dass Sie die "app_client_id" durch die tatsächliche App-Client-ID ersetzen (z. B. dcd68e75-54d4-xxxx-9dfb-xxxx3833ec1a, ohne '{' und '}'). Und stellen Sie sicher, dass Sie die "IhreDomain" durch Ihren tatsächlichen Domainnamen ersetzen. –