Skip to content

Commit f5b4518

Browse files
committed
ADServices
1 parent be9581d commit f5b4518

23 files changed

+2189
-10
lines changed

.github/workflows/validate-powershell.yml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
#
6-
# https://github.com/microsoft/action-psscriptanalyzer
7-
# For more information on PSScriptAnalyzer in general, see
1+
# this workflow uses https://github.com/microsoft/action-psscriptanalyzer . For
2+
# more information on PSScriptAnalyzer in general, see
83
# https://github.com/PowerShell/PSScriptAnalyzer
94

105
name: Powershell CI
@@ -56,13 +51,12 @@ jobs:
5651
with:
5752
sarif_file: results.sarif
5853

59-
# Run the tests
6054
- name: Install Pester
6155
shell: powershell
6256
run: |
6357
Install-Module -Name Pester -Force -Scope CurrentUser
6458
65-
- name: Run Pester Tests
59+
- name: Run Pester Unit Tests
6660
shell: powershell
6761
run: |
6862
$modules = Get-ChildItem -Directory -Path ./src
@@ -74,4 +68,24 @@ jobs:
7468
} else {
7569
"No tests found for module: $($module.Name). Skipping."
7670
}
77-
}
71+
}
72+
73+
- name: docker compose smblds
74+
uses: hoverkraft-tech/[email protected]
75+
with:
76+
compose-file: "./src/ADServices/Tests/Integration/adservices-testdocker/docker-compose.yml"
77+
services: smblds
78+
up-flags: wait
79+
80+
- name: Run Pester ADServices Integration Tests
81+
shell: powershell
82+
run: |
83+
$Server = 'localhost:389'
84+
$PSCredential = [PSCredential]::new('Administrator', (ConvertTo-SecureString 'Passw0rd' -AsPlainText -Force))
85+
86+
Invoke-Pester -Container (New-PesterContainer -ScriptBlock {
87+
$testsPath = '.\src\ADServices\Tests\Integration'
88+
ForEach ($testPath in Get-ChildItem $testsPath -Filter "*.tests.ps1") {
89+
& $testPath.FullName -Server $Server -PSCredential $PSCredential
90+
}
91+
})

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"cSpell.words": [
3+
"bitfield",
4+
"bitmask",
5+
"pcgeek",
6+
"psscriptanalyzer",
7+
"pwsh",
8+
"RSAT",
9+
"samdom",
10+
"sarif",
11+
"smblds"
12+
]
13+
}

src/ADServices/ADAccount.psm1

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Import-Module "$PSScriptRoot\Shared\SharedMetaModule.psm1" -Verbose:$false
2+
Set-StrictMode -Version Latest
3+
$ErrorActionPreference = [Management.Automation.ActionPreference]::Stop
4+
5+
6+
function Enable-ADAccount {
7+
[CmdletBinding(SupportsShouldProcess)]
8+
param (
9+
[Parameter(Mandatory, ValueFromPipeline)]
10+
[string] $Identity,
11+
[string] $Server,
12+
[PSCredential] $Credential,
13+
[switch] $PassThru
14+
)
15+
process {
16+
$entry = Get-ADUser -Server $Server -Credential $Credential -Identity $Identity
17+
if ($entry) {
18+
if ($PSCmdlet.ShouldProcess($Identity, "Enable-ADAccount")) {
19+
Write-Verbose "Enabling user account '$Identity'."
20+
Set-DirectoryEntryFlag $entry userAccountControl $UserAccountControl_ACCOUNT_DISABLED $false -Verbose:$VerbosePreference
21+
$entry.CommitChanges()
22+
}
23+
if ($PassThru) {
24+
Update-ADUserEntry $entry
25+
26+
# output
27+
$entry
28+
}
29+
} else {
30+
Write-Error "Account not found: $Identity"
31+
}
32+
}
33+
}
34+
35+
36+
function Disable-ADAccount {
37+
[CmdletBinding(SupportsShouldProcess)]
38+
param (
39+
[Parameter(Mandatory, ValueFromPipeline)]
40+
[string] $Identity,
41+
[string] $Server,
42+
[PSCredential] $Credential,
43+
[switch] $PassThru
44+
)
45+
process {
46+
$entry = Get-ADUser -Server $Server -Credential $Credential -Identity $Identity
47+
if ($entry) {
48+
if ($PSCmdlet.ShouldProcess($Identity, "Disable-ADAccount")) {
49+
Write-Verbose "Disabling user account '$Identity'."
50+
Set-DirectoryEntryFlag $entry userAccountControl $UserAccountControl_ACCOUNT_DISABLED $true -Verbose:$VerbosePreference
51+
$entry.CommitChanges()
52+
}
53+
if ($PassThru) {
54+
Update-ADUserEntry $entry
55+
56+
# output
57+
$entry
58+
}
59+
} else {
60+
Write-Error "Account not found: $Identity"
61+
}
62+
}
63+
}
64+
65+
Export-ModuleMember -Function *-ADAccount

0 commit comments

Comments
 (0)