# Commands to create AD environment

## Install AD Dependencies

### Windows Server Datacenter (GUI)

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2F5PljgjoYpM4jq41PWtkc%2Fimage.png?alt=media&#x26;token=ba72b452-1f8e-45f3-a75a-f16684904b8a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FXnkCX41QqpMRNVSXDk49%2Fimage.png?alt=media&#x26;token=e334abaa-3ffe-436b-a214-63470909c015" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FuX7eXWfeE9Ho5Rv44JKg%2Fimage.png?alt=media&#x26;token=2ce0e0df-b3fe-4d1f-857e-cd43ac3b9593" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FWKpK6hV3SuWXeFHB1YwA%2Fimage.png?alt=media&#x26;token=4ac6a5a8-65e4-4f90-ac43-8c5885f23f38" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2F4xiGM2kqIrV5UCEJ9IwD%2Fimage.png?alt=media&#x26;token=a879a1f2-7d7f-4a73-b5d4-8ca1c645f96a" alt=""><figcaption></figcaption></figure>

Next and Install.

### Windows Server Standard (CLI)

From here <https://medium.com/@serkanturan_79203/installing-active-directory-with-powershell-ea48de56088c>

Install AD DS (Active Directory Domain Services):

```powershell
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
```

Configure a new Forest:

```powershell
Import-Module ADDSDeployment
Install-ADDSForest -DomainName "lanz-corp.com" -InstallDNS
```

Verify installation:

```powershell
Get-Service adws,kdc,netlogon,dns
```

## Promote Server to Domain Controller (GUI)

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2Ffm2S0RAkgfhuEUhvPQrQ%2Fimage.png?alt=media&#x26;token=6802567c-f042-410a-88e2-bd3fdeba4f60" alt=""><figcaption></figcaption></figure>

Click on "Promote this server to a domain controller":

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FXjLwB30St1PGTsUHCE4j%2Fimage.png?alt=media&#x26;token=aed84e9f-b26f-426a-9469-78addeae560a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2F8LeAbDQ4pdQmWHr2SOXw%2Fimage.png?alt=media&#x26;token=bca76e75-3493-430b-bcdd-263ca415daf0" alt=""><figcaption><p>Domain name: freed-om-corp.com</p></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FZ0VwrWA95ZYYAdT83SBB%2Fimage.png?alt=media&#x26;token=01842fe2-4385-481c-b4d1-36639532dd38" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2F4mQMgkm18kcEOCsyKFGq%2Fimage.png?alt=media&#x26;token=68f09d50-1fd4-4f1a-92ab-893f1337a324" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FLK9LqhWwVKKK6Lchx4PO%2Fimage.png?alt=media&#x26;token=7ba846fd-633d-4f22-91a2-9d80a0f02059" alt=""><figcaption></figcaption></figure>

Install:

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FXd7F7ceLXboub8wJiax9%2Fimage.png?alt=media&#x26;token=89268f59-1407-4001-8300-d931c7053597" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2F1PKIMXtuYFrifSbrQlYM%2Fimage.png?alt=media&#x26;token=2ebcae53-4121-4332-9971-e3c883538a29" alt=""><figcaption></figcaption></figure>

The server has been promoted to a Domain Controller, and the authentication is now based in domain.

## Users

### Configure users, groups, machines...

```
Run from the start menu: Active Directory Users and Computers
```

### Get-ADUser (search users)

```powershell
Get-ADUser -Filter 'Name -like "*Paul*"'
Get-ADUser -Filter "Name -like '*Orion*'" -Properties *
```

```powershell
Get-ADUser -Filter 'Name -like "*Mike*"' | Format-Table Name,SamAccountName

Name           SamAccountName
----           --------------
Mike Andrews   Jectle1984
Mike Rocha     Trequievery
Mike Rosa      Mans1990
Mike Blackmon  Stemodgme01
Joshua Mikels  Wifen1938
Mike Goodwin   Lovicher
Mike Dukes     Imosed
Mike Bynum     Barve1947
Mike Pritchard Pludenis
Mike O'Hare    mohare
```

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/get-aduser?view=windowsserver2022-ps>" %}

### New-ADUser (add user)

Using the `Active Directory Users and Computers` from the start-menu and inside a folder or using PowerShell commands:

```powershell
New-ADUser -Name "Orion Starchaser" -DisplayName 'Orion Starchaser' -SamAccountName 'o.starchaser' -UserPrincipalName 'orion.starchaser@inlanefreight.local' -AccountPassword (Read-Host -AsSecureString 'Enter a password') -Enabled $true -ChangePasswordAtLogon $true -OtherAttributes @{'title'='analyst';'mail'='o.starchaser@inlanefreight.local'}
```

```powershell
Get-ADUser -Identity o.starchaser
```

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-aduser?view=windowsserver2022-ps>" %}

### Set-ADUser (update user info)

```powershell
Set-ADUser -Identity 'Artemis Callisto' -DisplayName 'Artemis Callisto'
```

```powershell
Get-ADUser -Filter "Name -like 'Andromeda Cepheus'" -Properties *

[...]
DistinguishedName : CN=Andromeda Cepheus,OU=Analysts,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
Enabled           : True
GivenName         : Andromeda
Name              : Andromeda Cepheus
ObjectClass       : user
ObjectGUID        : 300c377e-db3d-4da4-aabd-7235d69693ff
SamAccountName    : a.cepheus
SID               : S-1-5-21-3842939050-3880317879-2865463114-7604
Surname           : Cepheus
UserPrincipalName : a.cepheus@INLANEFREIGHT.LOCAL
[...]
EmailAddress      :
[...]
mail              :
[...]
```

Let's update the Email:

```powershell
Set-ADUser -Identity 'a.cepheus' -EmailAddress 'a.cepheus@inlanefreight.local'
```

<pre class="language-powershell"><code class="lang-powershell"><strong>Get-ADUser -Filter "Name -like 'Andromeda Cepheus'" -Properties *
</strong>
[...]
EmailAddress      : a.cepheus@inlanefreight.local
[...]
mail              : a.cepheus@inlanefreight.local
[...]
</code></pre>

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/set-aduser?view=windowsserver2022-ps>" %}

### Remove-ADUser (remove user)

```powershell
Get-ADUser -Filter "Name -like '*Orion*'" | Format-Table Name,SamAccountName
```

```
Name             SamAccountName
----             --------------
Orion Starchaser Orion Starchaser
```

```powershell
Remove-ADUser -Identity 'Orion Starchaser'
```

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FbWiT05Ygq4VAFKw795m9%2Fimage.png?alt=media&#x26;token=7712b820-3f5f-422c-bd85-59b194d011b5" alt=""><figcaption></figcaption></figure>

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/remove-aduser?view=windowsserver2022-ps>" %}

### Unlock-ADAccount (unlock user)

```powershell
Get-ADUser -Filter 'Name -like "*Masters*"'

DistinguishedName : CN=Adam Masters,OU=Interns,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
Enabled           : True
GivenName         : Adam
Name              : Adam Masters
ObjectClass       : user
ObjectGUID        : 56d0f2af-e8a0-4d12-a910-c55257c702a2
SamAccountName    : amasters
SID               : S-1-5-21-3842939050-3880317879-2865463114-6108
Surname           : Masters
UserPrincipalName : amasters@INLANEFREIGHT.LOCAL
```

```powershell
Unlock-ADAccount -Identity 'amasters'
Set-ADAccountPassword amasters -Reset -NewPassword (Read-Host -AsSecureString -Prompt 'New Password')
Set-ADUser -ChangePasswordAtLogon $true -Identity amasters
```

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/search-adaccount?view=windowsserver2022-ps>" %}

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/unlock-adaccount?view=windowsserver2022-ps>" %}

### Update credentials

```powershell
Set-ADAccountPassword username -Reset -NewPassword (Read-Host -AsSecureString -Prompt 'New Password') -Verbose
Set-ADUser -ChangePasswordAtLogon $true -Identity username -Verbose
```

### Change DoesNotRequirePreAuth Right

This permission is used in Kerberos and is related to ASREP-Roast attack.

**GUI**:

Enable "Do not require Kerberos preauthentication":

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FyAqONZjkbtyM2JLdHcj4%2Fimage.png?alt=media&#x26;token=8290958d-803c-4f79-847d-4133a0900bf8" alt=""><figcaption></figcaption></figure>

**CLI**:

We have a list of valid users:

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FpIStFi4cwMWF1WbgLOR2%2Fimage.png?alt=media&#x26;token=182c10f8-3d13-4821-b097-036424beaa92" alt=""><figcaption></figcaption></figure>

Does anyone have the DoesNotRequirePreAuth right?

```bash
python3 GetNPUsers.py -no-pass -usersfile users.txt -dc-ip 10.10.10.10 -format john -outputfile dc-freed-om-corp-asreproastable-users.txt 'lanz.com/'
```

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2Ff5FYDtSKcKL7T7IRdWWU%2Fimage.png?alt=media&#x26;token=f5f5229c-b9fb-4180-8b31-375cae40bbbb" alt=""><figcaption></figcaption></figure>

Nop.

Let's activate it...

```powershell
Get-ADUser -Identity paolo.suarez -Properties * | Format-Table Name,DoesNotRequierePreAuth
Get-ADUser -Identity paolo.suarez | Set-ADAccountControl -DoesNotRequirePreAuth $true
```

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FJwNC9op1p3A857LVnPO2%2Fimage.png?alt=media&#x26;token=0d20cdd3-6989-46c5-83ce-be21d8299a06" alt=""><figcaption></figcaption></figure>

Again, does anyone have the DoesNotRequirePreAuth right?

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FCnkkTO5tdKHpIkddhO6Y%2Fimage.png?alt=media&#x26;token=696e5ec9-782f-4dd0-9b25-d7088d2cce1b" alt=""><figcaption></figcaption></figure>

Yeah, there is one!

## Computers

### Add-Computer (add a computer to a domain)

In the new computer we are going to execute:

```powershell
Add-Computer -DomainName INLANEFREIGHT.LOCAL -Credential INLANEFREIGHT.LOCAL\htb-student_adm -Restart
```

Or remotely:

```powershell
Add-Computer -ComputerName ACADEMY-IAD-W10 -LocalCredential ACADEMY-IAD-W10\image -DomainName INLANEFREIGHT.LOCAL -Credential INLANEFREIGHT\htb-student_adm -Restart
```

It will generate a pop-up to input credentials of a Domain Admin (or if the user is already created in the Domain, we can set the user credentials instead of Administrator).

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2Fi0i6Lwwp1Nbe5RPsvOUh%2Fimage.png?alt=media&#x26;token=fceffdd1-902d-44a9-92c5-3da66a6d104d" alt=""><figcaption></figcaption></figure>

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/add-computer?view=powershell-5.1>" %}

### Move a computer to an OU

```powershell
Get-ADComputer -Identity 'ACADEMY-IAD-W10' | Move-ADObject -TargetPath 'OU=Security Analysts,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL'
```

### Remove-Computer

```powershell
Remove-Computer -ComputerName 'ACADEMY-IAD-W10' -UnjoinDomainCredential 'INLANEFREIGHT.LOCAL\htb-student_adm' -PassThru -Restart -Verbose
```

If doesn't work, do it manually in the local computer:

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-computer?view=powershell-5.1>" %}

{% embed url="<https://learn.microsoft.com/en-us/answers/questions/1387592/remove-computer-from-domain-using-powershell>" %}

## Group Policy Object (GPO)

### Configure Group Policy Object with GUI

```
Run from the start menu: Group Policy Management
```

### Force any particular computer to sync its GPOs

```powershell
gpupdate /force
```

### Copy-GPO (copy/duplicate a GPO)

```powershell
Get-GPO -All | FT Displayname
```

```powershell
Copy-GPO -SourceName 'Logon Banner' -TargetName 'Security Analysts Control'
```

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FR76sJhrM3dhcMpYhjHRv%2Fimage.png?alt=media&#x26;token=ef776ba0-2676-438d-ad49-867aa4dd7a3d" alt=""><figcaption></figcaption></figure>

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/grouppolicy/copy-gpo?view=windowsserver2022-ps>" %}

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/grouppolicy/new-gplink?view=windowsserver2022-ps>" %}

{% embed url="<https://community.spiceworks.com/t/mass-link-gpos-using-powershell/1012467>" %}

### New-GPLink (link a GPO to an OU)

```powershell
New-GPLink -Name 'Security Analysts Control' -Target 'OU=Security Analysts,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL' -LinkEnabled Yes
```

```powershell
Get-GPO -Name 'Security Analysts Control' | New-GPLink -Target 'OU=Security Analysts,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL' -LinkEnabled Yes
```

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FCbqqbxAbCKG5BBWNyzBL%2Fimage.png?alt=media&#x26;token=db2c6fdb-9583-4b83-921e-54b11f98a351" alt=""><figcaption></figcaption></figure>

## Organization Unit (OU)

### Get-ADOrganizationUnit (obtain OUs)

```powershell
Get-ADOrganizationalUnit -Filter 'Name -like "*"'
```

```powershell
Get-ADOrganizationalUnit -Filter 'Name -like "*HelpDesk*"'

City                     :
Country                  :
DistinguishedName        : OU=HelpDesk,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
LinkedGroupPolicyObjects : {}
ManagedBy                :
Name                     : HelpDesk
ObjectClass              : organizationalUnit
ObjectGUID               : 2ad47f9e-4550-44c6-bb99-104bc3ac2105
PostalCode               :
State                    :
StreetAddress            :
```

```powershell
Get-ADOrganizationalUnit -Identity 'OU=HelpDesk,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL'

City                     :
Country                  :
DistinguishedName        : OU=HelpDesk,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
LinkedGroupPolicyObjects : {}
ManagedBy                :
Name                     : HelpDesk
ObjectClass              : organizationalUnit
ObjectGUID               : 2ad47f9e-4550-44c6-bb99-104bc3ac2105
PostalCode               :
State                    :
StreetAddress            :
```

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/get-adorganizationalunit?view=windowsserver2022-ps>" %}

### Get members of an OU

```powershell
Get-ADuser -Filter * -SearchBase "OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL" | select name,DistinguishedName

[...]
Andromeda Cepheus  CN=Andromeda Cepheus,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
Artemis Callisto   CN=Artemis Callisto,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
Orion Starchaser   CN=Orion Starchaser,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL
```

{% embed url="<https://activedirectorypro.com/how-to-list-ad-users-from-a-specific-ou/>" %}

### New-ADOrganizationUnit (create an OU)

```powershell
New-ADOrganizationalUnit -Name 'Security Analysts' -Path 'OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL'
```

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2F0RxROkRkrWvE3p06KKAe%2Fimage.png?alt=media&#x26;token=c0e4ce88-5eec-48b8-b7ca-3b7b604383c7" alt=""><figcaption></figcaption></figure>

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-adorganizationalunit?view=windowsserver2022-ps>" %}

### Remove-ADOrganizationUnit (remove an OU)

```powershell
Get-ADOrganizationalUnit -Identity 'OU=Analysts,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL' | Set-ADObject -ProtectedFromAccidentalDeletion:$false -PassThru | Remove-ADOrganizationalUnit -Confirm:$false
```

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/remove-adorganizationalunit?view=windowsserver2022-ps>" %}

{% embed url="<https://www.itprotoday.com/powershell/delete-a-protected-ou-using-powershell>" %}

### Move-ADObject (to move an object (user, group, etc) to another OU)

```powershell
Move-ADObject -Identity "CN=Artemis Callisto,CN=Users,DC=INLANEFREIGHT,DC=LOCAL" -TargetPath "OU=Security Analysts,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL"
```

```powershell
Get-ADUser -Identity a.callisto | Move-ADObject -TargetPath 'OU=Security Analysts,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL'
```

{% embed url="<https://stackoverflow.com/questions/12712852/how-can-i-use-powershell-to-move-a-user-in-ad>" %}

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/move-adobject?view=windowsserver2022-ps>" %}

## Groups

### New-ADGroup (create a security group)

```powershell
New-ADGroup -Name "Security Analysts" -SamAccountName Analysts -GroupCategory Security -GroupScope Global -DisplayName "Security Analysts" -Path "OU=Security Analysts,OU=IT,OU=HQ-NYC,OU=Employees,OU=Corp,DC=INLANEFREIGHT,DC=LOCAL" -Description "Members of this group are Security Analysts under the IT OU"
```

* **Security groups**: Use to assign permissions to shared resources.
* **Distribution groups**: Use to create email distribution lists.

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-adgroup?view=windowsserver2022-ps>" %}

{% embed url="<https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/understand-security-groups>" %}

### Set-ADGroup (update group info)

```powershell
Set-ADGroup -Identity 'Analysts' -SamAccountName 'Security Analysts'
```

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/set-adgroup?view=windowsserver2022-ps>" %}

### Get-ADGroupMember (get members of a group)

```powershell
Get-ADGroupMember -Identity 'Security Analysts'
```

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/get-adgroupmember?view=windowsserver2022-ps>" %}

### Add-ADGroupMember (add members to a group)

```powershell
Add-ADGroupMember -Identity 'Security Analysts' -Members a.cepheus
Add-ADGroupMember -Identity 'Security Analysts' -Members 'Orion Starchaser','Artemis Callisto'
```

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2F1yBYwAKmn7zhWArjZrhf%2Fimage.png?alt=media&#x26;token=1fcaff4d-2b2d-41d4-9723-0ffde7d51fb6" alt=""><figcaption></figcaption></figure>

{% embed url="<https://learn.microsoft.com/en-us/powershell/module/activedirectory/add-adgroupmember?view=windowsserver2022-ps>" %}

## Shared Folders

### Create a shared folder

**GUI**:

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2F2yGgm39bm8iPMU1gTuC0%2Fimage.png?alt=media&#x26;token=88905454-128d-434b-ac77-12cd5c649f47" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FbPfB22l3EuqyOSvZcK24%2Fimage.png?alt=media&#x26;token=b70d43b8-717a-4663-8344-18351dc4dd90" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FMmpZXQni8hDaqUzYcBPl%2Fimage.png?alt=media&#x26;token=80c23b49-9f3f-49f8-a419-fe03972d525d" alt=""><figcaption></figcaption></figure>

Check "Type a custom path", and create a folder.

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FiLhyUdPqR8yOQi3G14LC%2Fimage.png?alt=media&#x26;token=d932058b-6684-4593-aa24-579c473b0873" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FZo4QNoApEGP0YMiEjDnD%2Fimage.png?alt=media&#x26;token=e64e9317-b8a7-4898-9d9f-98b4855d6bb5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FbG6SoURsLtgwSmCjcDgA%2Fimage.png?alt=media&#x26;token=09b970a9-3825-43eb-93cd-64d01a2be02f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2Fgo2kDkCYQLrQvpK8jP6F%2Fimage.png?alt=media&#x26;token=b207ae01-bb3d-4aa6-b117-58e2cdba1ceb" alt=""><figcaption></figcaption></figure>

* Click on "Customize permissions"
* And set a user  with full access (for test) over that folder

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FdJFBiIqO31WYQFvfzaaC%2Fimage.png?alt=media&#x26;token=5f2a4950-7684-4158-9803-ace27ba66bc0" alt=""><figcaption></figcaption></figure>

Create and we done:

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FSNb8ajWORgB1JuRps12c%2Fimage.png?alt=media&#x26;token=4c3812f6-3b3b-4759-9f35-0a08d561c1e9" alt=""><figcaption></figcaption></figure>

**CLI**:

```powershell
New-SmbShare -Name "Pagos" -Path "C:\Pagos" -FullAccess "lanz.com\jose.lopez"
```

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2F1wmwoWjb4blHJgUy9bVr%2Fimage.png?alt=media&#x26;token=82e62c38-ac83-4ca9-93e8-bb25b6c4e693" alt=""><figcaption></figcaption></figure>

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FGvwkNeE3QEbaqNJFoEEx%2Fimage.png?alt=media&#x26;token=e8550ca4-30ae-4ba6-9948-2f7d24d257f5" alt=""><figcaption></figcaption></figure>

And checking:

```bash
smbmap -H 10.10.10.10 -d lanz.com -u 'jose.lopez' -p 'Jose123!'
```

<figure><img src="https://344105405-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFJ8sxzGfhnecDpAjrc%2Fuploads%2FCrb6L3c47ynyHl2oyfHS%2Fimage.png?alt=media&#x26;token=557e929e-c30b-47fc-b5fc-965b33fb6e24" alt=""><figcaption></figcaption></figure>
