@@ -88,10 +88,10 @@ InModuleScope MSFT_xComputer {
8888 It ' should not throw' {
8989 {Get-TargetResource - Name $env: COMPUTERNAME } | Should Not Throw
9090 }
91- It ' Should return a hashtable containing Name,DomainName, Credential, UnjoinCredential and WorkGroupName' {
91+ It ' Should return a hashtable containing Name, DomainName, JoinOU, CurrentOU , Credential, UnjoinCredential and WorkGroupName' {
9292 $Result = Get-TargetResource - Name $env: COMPUTERNAME
9393 $Result.GetType ().Fullname | Should Be ' System.Collections.Hashtable'
94- $Result.Keys | Should Be @ (' Name' , ' DomainName' , ' Credential' , ' UnjoinCredential' , ' WorkGroupName' )
94+ $Result.Keys | Should Be @ (' Name' , ' DomainName' , ' JoinOU ' , ' CurrentOU ' , ' Credential' , ' UnjoinCredential' , ' WorkGroupName' )
9595 }
9696 }
9797 Context Set-TargetResource {
@@ -115,6 +115,14 @@ InModuleScope MSFT_xComputer {
115115 Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName -and $NewName }
116116 Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
117117 }
118+ It ' Changes ComputerName and changes Domain to new Domain with specified OU' {
119+ Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso.com' ;Workgroup = ' Contoso.com' ;PartOfDomain = $true }}
120+ Mock GetComputerDomain {' contoso.com' }
121+ Set-TargetResource - Name $NotComputerName - DomainName ' adventure-works.com' - JoinOU ' OU=Computers,DC=contoso,DC=com' - Credential $Credential - UnjoinCredential $Credential | Should BeNullOrEmpty
122+ Assert-MockCalled - CommandName Rename-Computer - Exactly 0 - Scope It
123+ Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName -and $NewName }
124+ Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
125+ }
118126 It ' Changes ComputerName and changes Domain to Workgroup' {
119127 Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso.com' ;Workgroup = ' Contoso.com' ;PartOfDomain = $true }}
120128 Mock GetComputerDomain {' contoso.com' }
@@ -131,6 +139,14 @@ InModuleScope MSFT_xComputer {
131139 Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName -and $NewName }
132140 Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
133141 }
142+ It ' Changes ComputerName and changes Workgroup to Domain with specified OU' {
143+ Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso' ;Workgroup = ' Contoso' ;PartOfDomain = $false }}
144+ Mock GetComputerDomain {' ' }
145+ Set-TargetResource - Name $NotComputerName - DomainName ' Contoso.com' - JoinOU ' OU=Computers,DC=contoso,DC=com' - Credential $Credential | Should BeNullOrEmpty
146+ Assert-MockCalled - CommandName Rename-Computer - Exactly 0 - Scope It
147+ Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName -and $NewName }
148+ Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
149+ }
134150 It ' Changes ComputerName and changes Workgroup to new Workgroup' {
135151 Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso' ;Workgroup = ' Contoso' ;PartOfDomain = $false }}
136152 Mock GetComputerDomain {' ' }
@@ -148,6 +164,15 @@ InModuleScope MSFT_xComputer {
148164 Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$NewName }
149165 Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
150166 }
167+ It ' Changes only the Domain to new Domain with specified OU' {
168+ Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso.com' ;Workgroup = ' Contoso.com' ;PartOfDomain = $true }}
169+ Mock GetComputerDomain {' contoso.com' }
170+ Set-TargetResource - Name $Env: ComputerName - DomainName ' adventure-works.com' - JoinOU ' OU=Computers,DC=contoso,DC=com' - Credential $Credential - UnjoinCredential $Credential | Should BeNullOrEmpty
171+ Assert-MockCalled - CommandName Rename-Computer - Exactly 0 - Scope It
172+ Assert-MockCalled - CommandName Add-Computer - Exactly 1 - Scope It - ParameterFilter {$DomainName }
173+ Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$NewName }
174+ Assert-MockCalled - CommandName Add-Computer - Exactly 0 - Scope It - ParameterFilter {$WorkGroupName }
175+ }
151176 It ' Changes only Domain to Workgroup' {
152177 Mock Get-WMIObject {[PSCustomObject ]@ {Domain = ' Contoso.com' ;Workgroup = ' Contoso.com' ;PartOfDomain = $true }}
153178 Mock GetComputerDomain {' ' }
0 commit comments