Changing credentials for a managed domain
Change Active Directory domain credentials
The following code sample changes the credentials used by Adaxes to perform operations within an Active Directory domain.
- PowerShell
-
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") $domainName = "example.com" $username = "administrator@example.com" $password = "secret" # Connect to the Adaxes service. $ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace" $service = $ns.GetServiceDirectly("localhost") # Build ADS path to the managed domain. $managedDomainsPath = $service.Backend.GetConfigurationContainerPath("ManagedDomains") $managedDomainsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $managedDomainsPath $managedDomainPath = $managedDomainsPathObj.CreateChildPath("DC=$domainName") # Bind to the domain. $managedDomain = $service.OpenObject($managedDomainPath, $null, $null, 0) # Update logon information. $managedDomain.Register($username, $password)
- C#
-
using System; using Softerra.Adaxes.Adsi; using Softerra.Adaxes.Interop.Adsi.PersistentObjects; class Program { static void Main(string[] args) { const string domainName = "example.com"; const string username = "administrator@example.com"; const string password = "secret"; // Connect to the Adaxes service. AdmNamespace ns = new AdmNamespace(); IAdmService service = ns.GetServiceDirectly("localhost"); // Build ADS path to the managed domain. string managedDomainsPath = service.Backend.GetConfigurationContainerPath( "ManagedDomains"); AdsPath managedDomainsPathObj = new AdsPath(managedDomainsPath); AdsPath managedDomainPath = managedDomainsPathObj.CreateChildPath($"DC={domainName}"); // Bind to the domain. IAdmManagedDomain managedDomain = (IAdmManagedDomain)service.OpenObject( managedDomainPath.ToString(), null, null, 0); // Update logon information. managedDomain.Register(username, password); } }
Change Microsoft Entra domain credentials
The following code sample changes the application identifier and client secret used by Adaxes to perform operations within an Entra domain.
- PowerShell
-
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi") $domainName = "example.onmicrosoft.com" $applicationID = "0db3e0b9-6d5e-41a3-9b52-daf859129da2" $secret = "1xYfgT7!qW94bLz@J8d#MnvP2kXeCuR0sFgUoAH3tZpLViEY6Q" # Connect to the Adaxes service. $ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace" $service = $ns.GetServiceDirectly("localhost") # Build ADS path to the managed domain. $managedDomainsPath = $service.Backend.GetConfigurationContainerPath("ManagedDomains") $managedDomainsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $managedDomainsPath $managedDomainPath = $managedDomainsPathObj.CreateChildPath("DC=$domainName") # Bind to the domain. $managedDomain = $service.OpenObject($managedDomainPath, $null, $null, 0) # Update logon information. $managedDomain.Register( $managedDomain.TenantId, $applicationId, $secret, $managedDomain.NationalCloud)
- C#
-
using System; using Softerra.Adaxes.Adsi; using Softerra.Adaxes.Interop.Adsi.PersistentObjects; class Program { static void Main(string[] args) { const string domainName = "example.onmicrosoft.com"; const string applicationId = "0db3e0b9-6d5e-41a3-9b52-daf859129da2"; const string secret = "1xYfgT7!qW94bLz@J8d#MnvP2kXeCuR0sFgUoAH3tZpLViEY6Q"; // Connect to the Adaxes service. AdmNamespace ns = new AdmNamespace(); IAdmService service = ns.GetServiceDirectly("localhost"); // Build ADS path to the managed domain. string managedDomainsPath = service.Backend.GetConfigurationContainerPath("ManagedDomains"); AdsPath managedDomainsPathObj = new AdsPath(managedDomainsPath); AdsPath managedDomainPath = managedDomainsPathObj.CreateChildPath($"DC={domainName}"); // Bind to the domain. IAdmAzureManagedDomain managedDomain = (IAdmAzureManagedDomain)service.OpenObject( managedDomainPath.ToString(), null, null, 0); // Update logon information. managedDomain.Register( managedDomain.TenantId.ToString(), applicationId, secret, managedDomain.NationalCloud); } }
See also
- Writing ADSI scripts
- Server-side scripting
- IAdmTop
- IAdmManagedDomain
- IAdmAzureManagedDomain
- IAdmManagedDomainInfo
- Adding domains
- Online script repository