Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Interop.ActiveDs is a .NET framework interoperability feature that allows PowerShell to interact with Active Directory objects. To utilize Interop.ActiveDs in PowerShell, you need to follow the below steps:

  1. Import the ActiveDs assembly: You can import the ActiveDs assembly by using the Add-Type cmdlet in PowerShell. The command for importing the assembly is:

Add-Type -AssemblyName "ActiveDs"

  1. Create an Active Directory object: To create an Active Directory object, you need to use the [ADSI] type accelerator followed by the LDAP path of the object. For example, to create an object for a user named "John" in the "Sales" OU, the command will be:

$user = [ADSI]"LDAP://CN=John,OU=Sales,DC=contoso,DC=com"

  1. Query Active Directory objects: You can use the Interop.ActiveDs library to query Active Directory objects using the ADSI search filter. For example, to retrieve all group objects from the Active Directory, you can use the following command:

$searcher = New-Object Interop.ActiveDs.ADSIsearcher $searcher.filter = "(objectClass=group)" $groups = $searcher.FindAll()

  1. Modify Active Directory objects: To modify Active Directory objects, you can use the Interop.ActiveDs library's methods and properties. For example, to change the password of a user object, you can use the IADsUser.SetPassword method:

$user = [ADSI]"LDAP://CN=John,OU=Sales,DC=contoso,DC=com" $user.SetPassword("NewPassword")

In summary, Interop.ActiveDs is a powerful library that can be utilized in PowerShell to interact with Active Directory objects. By following the above steps, you can create, query, and modify Active Directory objects using PowerShell.