Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Options parameter to Computer resource #381

Merged
merged 33 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3b873c7
Adding options to commands
nickgw Apr 7, 2022
21022b1
adding option sto schema
nickgw Apr 7, 2022
222fad0
updating changelog.md
nickgw Apr 7, 2022
5f31e68
validateset and add localized errors
Apr 7, 2022
bfb800f
updating error message
Apr 7, 2022
ea2fa03
updating values in mof
Apr 7, 2022
9b66124
Merge remote-tracking branch 'origin/main' into ngermany_adddomainjoi…
nickgw Apr 11, 2022
d65c47d
Simplifying options parsing
Apr 12, 2022
2f9d367
fixing type in schema
Apr 12, 2022
d7b0925
Updating if statements to match rules
Apr 12, 2022
755521f
Adding tests
Apr 12, 2022
34b5b7a
fixing tests
Apr 12, 2022
fcacef9
add error record
Apr 12, 2022
5ec884e
Updating parameters to mock error message
Apr 12, 2022
4074396
use correct error func
Apr 12, 2022
87a96d6
use correct error func
Apr 12, 2022
5cc4b3e
why was i splatting
Apr 12, 2022
9b6136f
why wont this build
Apr 12, 2022
d0de6c9
Using invalidargumentrecord
nickgw Apr 12, 2022
3f559b3
Use assert-resourceproperty
Apr 12, 2022
50383da
fixing merge conflict
Apr 12, 2022
f684b72
Updating without errorRecord
Apr 12, 2022
4c809dd
reverting settings change
Apr 12, 2022
d363a85
re-adding errorrecord
Apr 12, 2022
842ecd8
Fixing unit tests for computer
nickgw Apr 23, 2022
482c191
fixing assertion for null username
nickgw Apr 23, 2022
57c7446
Use correct parameter in assert-resourceproperty
nickgw Apr 23, 2022
487a999
fix hashtable
nickgw Apr 23, 2022
203290a
pass credential
nickgw Apr 23, 2022
322e0c7
no need for machine password anymore
nickgw Apr 23, 2022
82c362e
Updating syntax and adding a test for passing Options to set
nickgw May 13, 2022
7877c5d
Fixing with backtick
nickgw May 13, 2022
18c0c22
Reformatting
nickgw May 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Computer
- Support Options Parameter for domain join - Fixes [Issue #234](https://github.com/dsccommunity/ComputerManagementDsc/issues/234).

## [8.5.0] - 2021-09-13

### Added
Expand Down
42 changes: 39 additions & 3 deletions source/DSCResources/DSC_Computer/DSC_Computer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ function Get-TargetResource

[Parameter()]
[System.String]
$Server
$Server,

[Parameter()]
[System.String()]
$Options
)

Write-Verbose -Message ($script:localizedData.GettingComputerStateMessage -f $Name)
Expand Down Expand Up @@ -188,7 +192,11 @@ function Set-TargetResource

[Parameter()]
[System.String]
$Server
$Server,

[Parameter()]
[System.String()]
$Options
)

Write-Verbose -Message ($script:localizedData.SettingComputerStateMessage -f $Name)
Expand Down Expand Up @@ -247,6 +255,30 @@ function Set-TargetResource
$addComputerParameters.Add("Server", $Server)
}

if (-not [System.String]::IsNullOrEmpty($Options)){
<#
See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/add-computer?view=powershell-5.1#parameters for available options and their description
#>
$joinOptions = New-Object System.Collections.Generic.List[string]
$available_options = @("AccountCreate","Win9XUpgrade","UnsecuredJoin","PasswordPass","JoinWithNewName","JoinReadOnly","InstallInvoke")
foreach ($option in $Options) {
if ($option -in $available_options) {
if ($option -eq 'PasswordPass') {
if ('UnsecuredJoin' -in $Options) {
# PasswordPass must be used in conjunction with UnsecuredJoin
if ([System.String]::IsNullOrEmpty($Credential.UserName)){
$joinOptions.Add($option)
}
} else {
New-InvalidOperationException -Message "PasswordPass is valid only when teh UnsecuredJoin option is specified"
nickgw marked this conversation as resolved.
Show resolved Hide resolved
}
}
$joinOptions.Add($option)
}
}
$addComputerParameters.Add("Options", $joinOptions)
}

# Rename the computer, and join it to the domain.
try
{
Expand Down Expand Up @@ -461,7 +493,11 @@ function Test-TargetResource

[Parameter()]
[System.String]
$Server
$Server,

[Parameter()]
[System.String()]
$Options
)

Write-Verbose -Message ($script:localizedData.TestingComputerStateMessage -f $Name)
Expand Down
2 changes: 2 additions & 0 deletions source/DSCResources/DSC_Computer/DSC_Computer.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ class DSC_Computer : OMI_BaseResource
[Write, Description("The name of the workgroup.")] String WorkGroupName;
[Write, Description("The value assigned here will be set as the local computer description.")] String Description;
[Write, Description("The Active Directory Domain Controller to use to join the domain")] String Server;
[Write, Description("Specifies advanced options for the Add-Computer join operation")] String Options;
[Read, Description("A read-only property that specifies the organizational unit that the computer account is currently in.")] String CurrentOU;
};