Skip to content
July 24, 2026
  • Linkedin
  • Twitter
  • Facebook
  • Youtube

Daily CyberSecurity

Zero-hour alerts. Unmatched analysis.

Primary Menu
  • Home
  • CVE Data
    • CVE Watchtower
    • Top Exploited CVEs
    • CVE Stats by Vendor
    • Q2 2026 Report
  • Cyber Criminals
  • Data Leak
  • Linux
  • Malware
  • Vulnerability
  • Submit Press Release
  • Weekly Recap
Light/Dark Button
  • Home
  • Technique
  • Use powershell to manage domain users
  • Technique

Use powershell to manage domain users

Do Son June 2, 2017 4 minutes read

In the domain environment, often need to use the command line management domain users, then you can use the Active Directory command line tools Dsquery.exe, or CSVE, and Ldifde, in fact, the use of Windows Powershell to manage the operation is quite convenient.

The following to create a user example: Create a domain user The most basic Windows Powershell script looks like this:

$objOU=[ADSI]”LDAP://OU=People,DC=contoso,DC=com”

$objUser=$objU.Create(“user”,”CN=Mary North”)
$odjUser.Put=(“sAMAccountName”,”mary.north”)
$objUser.SetInfo()

The above code lists the four basic steps for creating a user using Active Directory using Windows Powershell.
The details will be described below.

Connect to the Active Directory container

To create an object like this, it is actually going to create an object for the object’s container. So the first need for the container, the implementation of a certain operation, that is, “method.” The first step is to connect to the container, and Windows Powershell can use the Active Directory service interface type adapter to cut into the Active Directory object. To connect to an Active Directory object, you must submit an LDAP query string, that is, the LDAP: // protocol identifier followed by the object’s DN. So the first line of code should look like this:

$objOU=[ADSI]"LDAP://OU=People,DC=contoso,DC=com"

Windows Powershell needs to use the ADSI type adapter to create objects that represent the People OU and assign it to the component. A variable named objOU reflects the identification of a variable type, starting with obj just a programming standard, but the actual variable can use any name.

Call the Create method

At this point, the variable $ objOU can represent the People OU. You can then use the container’s create method to let the container create the object. The Create method needs to provide two parameters: the object class and the object RDN. The object’s RDN refers to the name of the object under the parent container, and most object classes use the “CN = object name” format as its own RDN. However, the RDN of the OU is in the format “OU = organizational unit name”, and the domain’s RDN is “DN = domain name”. So the following code can use the “CN = Mary North” RDN to create user objects:

$objUser=$objU.Create("user","CN=Mary North")

The resulting object result is assigned to the variable $objUser and uses the variable to represent the object to be created for subsequent operations.

Fill in the user attributes

It is important to note that a new object and its changes are not saved until the changes are merged, and the changes can not be successfully merged before filling in all the necessary attributes. User object must be comfortable including windows 2000 before the login name. The LDAP name of the attribute is sAMAccountName, so the next line of code needs to assign sAMAccountName to the object, and you need to use the Put method. Put is the standard method for writing properties to an object, and Get is the standard method for retrieving object properties. The code here should look like this:

$odjUser.Put=("sAMAccountName","Mary North")

For user objects, there are other mandatory attributes, including the object’s security identifier (SID), but these objects will be automatically created when Active Directory is created when the new user is submitted to the directory.

Using the SetInfo method to merge changes

To merge changes, use the SetInfo method of the Active Directory object. The code here should look like this:

$objUser.SetInfo()

Fill in other user attributes

The above command creates a user that only contains the mandatory sAMAccountName attribute. When creating a user object, you also need to fill in other user attributes. Previously, the use of the user object Put method to write attributes, so here only need to repeatedly call the method, specify the need to add each attribute can be:

$odjUser.Put=(“sAMAccountName”, ”$samAccountName”)

$odjUser.Put=(“displayName”, ”$displayname”)
$odjUser.Put=(“sn”, “$sn”)
$objUser.SetInfo()

What is the user’s password? You can not set the user password using the Put method. Instead, you should use the SetPassword method, for example:

$objUser.SetPassword("passwd")

However, the SetPassword method can only be used after creating a user and calling the SetInfo () method, which means that in fact, we are the preferred to create a good account and then set a password for it. This is not a Windows Powershell bug or limitation, but the actual requirements for Kerberos and LDAP. However, security is not compromised because the account created is disabled.
So the status of the account is actually a flag (flag), can not be directly used Put command settings. The following commands are required:

$objUser.psbase.InvokeSet(“AccountDisabled”,$false)

$objUser.SetInfo()

 

Share this article:

Facebook Post LinkedIn Telegram
Tags: powershell

Search

Translation

CVE WATCHTOWER
🚨

Receive alerts for vulnerabilities being exploited in the wild.

⚡

Get notified instantly when a Proof of Concept (PoC) exploit is published.

🔍

Access critical info on vulnerabilities even when marked as "RESERVED".

🧠

Insights powered by decades of expertise and global intelligence sources.

🎯

Customize alerts with up to 10 keywords for your specific tech stack.

📊

Export the raw CVE database for SIEM integration and reporting.

Upgrade Package

🚨 Active Exploits in the Wild

  • CVE-2026-16232CVSS 9.1
    An authentication bypass vulnerability in the Check Point SmartConsole login process allows an unauthenticated remote attacker to obtain...
    CISA KEV📅 Added to KEV: Jul 22, 2026
  • CVE-2026-50522CVSS 9.8
    Deserialization of untrusted data in Microsoft Office SharePoint allows an unauthorized attacker to execute code over a network.
    Admin intelCISA KEV📅 Added to KEV: Jul 22, 2026📅 Updated: Jul 21, 2026
  • CVE-2026-63030CVSS 9.8
    WordPress 6.9.x before 6.9.5 and 7.0.x before 7.0.2 is affected by a REST API batch endpoint route confusion...
    Admin intelCISA KEV📅 Added to KEV: Jul 21, 2026📅 Updated: Jul 21, 2026
  • CVE-2026-60137CVSS 5.9
    WordPress 6.8.x before 6.8.6, 6.9.x before 6.9.5, and 7.0.x before 7.0.2 does not properly sanitise the author__not_in parameter...
    Admin intelCISA KEV📅 Added to KEV: Jul 21, 2026📅 Updated: Jul 21, 2026
  • CVE-2026-0770CVSS 9.8
    Langflow exec_globals Inclusion of Functionality from Untrusted Control Sphere Remote Code Execution Vulnerability. This vulnerability allows remote attackers...
    CISA KEV📅 Added to KEV: Jul 21, 2026
  • CVE-2021-27137CVSS 8.1
    An issue was discovered in router/upnp/src/ssdp.c in DD-WRT before 45724. An unsafe strcpy in the UPnP handling functionality...
    CISA KEV📅 Added to KEV: Jul 21, 2026
  • CVE-2026-6875CVSS 9.5
    ServiceNow has addressed a remote code execution vulnerability that was identified in the ServiceNow AI platform. This vulnerability...
    Admin intel📅 Updated: Jul 18, 2026
  • CVE-2026-39808CVSS 9.8
    A improper neutralization of special elements used in an os command ('os command injection') vulnerability in Fortinet FortiSandbox...
    CISA KEV📅 Added to KEV: Jul 16, 2026
Powered by CVE Watchtower

🔴 Live Critical Threats

  • CVE-2026-15704CVSS 9.8
    In Eclipse BaSyx Go Components versions up to and including 1.0.0, ABAC-enabled...
  • CVE-2026-62825CVSS 10.0
    Improper authentication in Azure Key Vault allows an unauthorized attacker to elevate...
  • CVE-2026-58275CVSS 10.0
    Missing authorization in Azure DNS allows an unauthorized attacker to elevate privileges...
  • CVE-2026-56191CVSS 10.0
    Improper authentication in Microsoft Exchange Online allows an unauthorized attacker to perform...
  • CVE-2026-56165CVSS 9.8
    Heap-based buffer overflow in Microsoft Account allows an unauthorized attacker to execute...
  • CVE-2026-56160CVSS 9.1
    Improper authorization in Azure Red Hat OpenShift (ARO) allows an authorized attacker...
  • CVE-2026-54120CVSS 9.9
    Improper input validation in Microsoft Surface allows an authorized attacker to execute...
  • CVE-2026-50517CVSS 9.9
    Deserialization of untrusted data in M365 Copilot allows an authorized attacker to...
  • CVE-2026-63359CVSS 9.8
    The Appriss Insights (Equifax) Victim Information Notification Exchange (VINE) applications allow an...
  • CVE-2026-6516CVSS 10.0
    Zohocorp ManageEngine ADAudit Plus versions before 8606 are affected by Unauthenticated Remote code...
Powered by CVE WATCHTOWER

Our Websites
  • Penetration Testing Tools
  • The Daily Information Technology
  • Top Exploited CVEs
  • Daily CyberSecurity

    • About SecurityOnline.info
    • Advertise with us
    • Announcement
    • Contact
    • Contributor Register
    • Login
    • Disclaimer
    • DCMA
    • Privacy Policy
    • About SecurityOnline.info
    • Advertise on SecurityOnline.info
    • Contact Us

    When you purchase through links on our site, we may earn an affiliate commission. Here’s how it works

    • CVE Watchtower
    • CVE Statistics by Vendor 2026
    • Q2 2026 Report
    • Top Exploited CVEs
    • Linkedin
    • Twitter
    • Facebook
    • Youtube
    © 2017 - 2026 Daily CyberSecurity. All Rights Reserved.