From 09df05d6f413b3072a8773e19f0c22d9dbef3e1f Mon Sep 17 00:00:00 2001 From: KarolKaczmarek Date: Wed, 12 Aug 2015 13:49:34 -0700 Subject: [PATCH 01/19] Create nuget package --- appveyor.yml | 63 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 62d98c28..5229559e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,25 @@ +#---------------------------------# +# environment configuration # +#---------------------------------# +version: 1.3.0.{build} install: - - cinst -y pester - - git clone https://github.com/PowerShell/DscResource.Tests + - cinst -y pester + - git clone https://github.com/PowerShell/DscResource.Tests + - ps: Push-Location + - cd DscResource.Tests + - ps: Import-Module .\TestHelper.psm1 -force + - ps: Pop-Location + +#---------------------------------# +# build configuration # +#---------------------------------# build: false +#---------------------------------# +# test configuration # +#---------------------------------# + test_script: - ps: | $testResultsFile = ".\TestsResults.xml" @@ -12,14 +28,37 @@ test_script: if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed." } -on_finish: - - ps: | - $stagingDirectory = (Resolve-Path ..).Path - $zipFile = Join-Path $stagingDirectory "$(Split-Path $pwd -Leaf).zip" - Add-Type -assemblyname System.IO.Compression.FileSystem - [System.IO.Compression.ZipFile]::CreateFromDirectory($pwd, $zipFile) - @( - # You can add other artifacts here - (ls $zipFile) - ) | % { Push-AppveyorArtifact $_.FullName } + +#---------------------------------# +# deployment configuration # +#---------------------------------# + +# scripts to run before deployment +before_deploy: + - ps: | + # Creating project artifact + $stagingDirectory = (Resolve-Path ..).Path + $manifest = Join-Path $pwd "xComputerManagement.psd1" + (Get-Content $manifest -Raw).Replace("1.3.0", $env:APPVEYOR_BUILD_VERSION) | Out-File $manifest + $zipFilePath = Join-Path $stagingDirectory "$(Split-Path $pwd -Leaf).zip" + Add-Type -assemblyname System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::CreateFromDirectory($pwd, $zipFilePath) + + # Creating NuGet package artifact + New-Nuspec -packageName $env:APPVEYOR_PROJECT_NAME -version $env:APPVEYOR_BUILD_VERSION -author "Microsoft" -owners "Microsoft" -licenseUrl "https://github.com/PowerShell/DscResources/blob/master/LICENSE" -projectUrl "https://github.com/$($env:APPVEYOR_REPO_NAME)" -packageDescription $env:APPVEYOR_PROJECT_NAME -tags "DesiredStateConfiguration DSC DSCResourceKit" -destinationPath . + nuget pack ".\$($env:APPVEYOR_PROJECT_NAME).nuspec" -outputdirectory . + $nuGetPackageName = $env:APPVEYOR_PROJECT_NAME + "." + $env:APPVEYOR_BUILD_VERSION + ".nupkg" + $nuGetPackagePath = (Get-ChildItem $nuGetPackageName).FullName + + @( + # You can add other artifacts here + $zipFilePath, + $nuGetPackagePath + ) | % { + Write-Host "Pushing package $_ as Appveyor artifact" + Push-AppveyorArtifact $_ + } + + + From 8f47d6a6c7c36198e54ca02d2934a0fd299fe64e Mon Sep 17 00:00:00 2001 From: KarolKaczmarek Date: Mon, 24 Aug 2015 17:02:44 -0700 Subject: [PATCH 02/19] Moving build number to the third section of version --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 5229559e..599bd19a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ #---------------------------------# # environment configuration # #---------------------------------# -version: 1.3.0.{build} +version: 1.3.{build}.0 install: - cinst -y pester - git clone https://github.com/PowerShell/DscResource.Tests From c8320ff8bd21d0c34423e2eaca875d2fde359635 Mon Sep 17 00:00:00 2001 From: prahlm93 Date: Tue, 20 Oct 2015 12:26:34 -0400 Subject: [PATCH 03/19] Added the ability to specify an OU upon joining to the Domain --- .../MSFT_xComputer/MSFT_xComputer.psm1 | 37 ++++++++++++++++-- .../MSFT_xComputer/MSFT_xComputer.schema.mof | Bin 326 -> 788 bytes 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 b/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 index 92056ffd..b71f2233 100644 --- a/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 +++ b/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 @@ -13,6 +13,8 @@ function Get-TargetResource [string] $DomainName, + [string] $JoinOU, + [PSCredential] $Credential, [PSCredential] $UnjoinCredential, @@ -26,6 +28,8 @@ function Get-TargetResource $returnValue = @{ Name = $env:COMPUTERNAME DomainName = GetComputerDomain + JoinOU = $JoinOU + CurrentOU = GetComputerOU Credential = [ciminstance]$convertToCimCredential UnjoinCredential = [ciminstance]$convertToCimUnjoinCredential WorkGroupName= (gwmi WIN32_ComputerSystem).WorkGroup @@ -42,6 +46,8 @@ function Set-TargetResource [string] $Name, [string] $DomainName, + + [string] $JoinOU, [PSCredential] $Credential, @@ -73,7 +79,12 @@ function Set-TargetResource } else { - Add-Computer -DomainName $DomainName -Credential $Credential -NewName $Name -Force + if ($JoinOU) { + Add-Computer -DomainName $DomainName -Credential $Credential -NewName $Name -OUPath $JoinOU -Force + } + else { + Add-Computer -DomainName $DomainName -Credential $Credential -NewName $Name -Force + } } Write-Verbose -Message "Renamed computer to '$($Name)' and added to the domain '$($DomainName)." } @@ -86,7 +97,12 @@ function Set-TargetResource } else { - Add-Computer -DomainName $DomainName -Credential $Credential -Force + if ($JoinOU) { + Add-Computer -DomainName $DomainName -Credential $Credential -OUPath $JoinOU -Force + } + else { + Add-Computer -DomainName $DomainName -Credential $Credential -Force + } } Write-Verbose -Message "Added computer to domain '$($DomainName)." } @@ -182,6 +198,8 @@ function Test-TargetResource ( [parameter(Mandatory)] [string] $Name, + + [string] $JoinOU, [PSCredential]$Credential, @@ -247,5 +265,18 @@ function GetComputerDomain } } -Export-ModuleMember -Function *-TargetResource +function GetComputerOU +{ + $ou = $null + if (GetComputerDomain) + { + $dn = $null + $dn = ([adsisearcher]"(&(objectCategory=computer)(objectClass=computer)(cn=$env:COMPUTERNAME))").FindOne().Properties.distinguishedname + $ou = $dn -replace '^(CN=.*?(?<=,))', '' + } + + return $ou +} + +Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_xComputer/MSFT_xComputer.schema.mof b/DSCResources/MSFT_xComputer/MSFT_xComputer.schema.mof index ef592e058c73a74e2655ff43d542af6a686c96f0..ddf833ff1c7fd85f39e6f410c3e937a0278ff32d 100644 GIT binary patch literal 788 zcmchV%}WAN6vfXv=zn;)Dv+pc?HV-UW=(GBX=n#ADva zymQXI=ic}A*-@m4Vl5bL4V1Dbn#t=#C0*!D=X{&Bq*ImUR0EZO_3Fc2>kj^uvoYS# zn{k?JrDf1F*0YXvq~32Nr-mNTdDKe*!|9SJO)z!tuS0eN-J`ZZdqwmfdsBQ5vjc6T zqcQ*2L~|gQAxp0zr=JY3GWgeku{`sfO7Icm)c=Wp3*Wd+wUmvU5;3NF`KVFwXZIcl zMciG^WmTzk7i^zla~+mBk6Eoo){$MMBitHlqn&`7aBtmlbYs6>MaZm&|Hz|-kI}Y{ Zhvk&7>=QaEFXV>VUeP?$)sJnLz5%x}f_VS{ literal 326 zcmb7;O$&lR5Qgvmip7&cL|yZiec-`@?Bft3n>)m&&dTgcN%Y^-1dHg>z+B#!dFDC# zIoEm*q@_Z~9uG&uW^H%C79;^hUaxooj(zi0QC0@Xc4I4TZ&(;Dwn?9}30sFjGUXaJ zpjAaFSa*vxbIhQQnKmTx%vze)#aEIB`eLREF7dk_%!?BU0U|(cIHrxs>#a{90FC5% hQxVlvL&gi>}(&N^#n2aZNmTn From e1442c9a12c20a2caf2188cc3dfd22438db8ef6b Mon Sep 17 00:00:00 2001 From: prahlm93 Date: Tue, 20 Oct 2015 12:29:57 -0400 Subject: [PATCH 04/19] Updated the readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fb1beb55..8d3cf9db 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,10 @@ xComputer resource has following properties: * Name: The desired computer name * DomainName: The name of the domain to join +* JoinOU: The distinguished name of the organizational unit that the computer account will be created in * WorkGroupName: The name of the workgroup * Credential: Credential to be used to join or leave domain +* CurrentOU: A read-only property that specifies the organizational unit that the computer account is currently in ## Versions From e961a1a05f30a85800e64336d5778a28bcada772 Mon Sep 17 00:00:00 2001 From: prahlm93 Date: Tue, 20 Oct 2015 12:34:55 -0400 Subject: [PATCH 05/19] Updated test --- Tests/xComputermanagement.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/xComputermanagement.Tests.ps1 b/Tests/xComputermanagement.Tests.ps1 index 5166519e..8822dd3f 100644 --- a/Tests/xComputermanagement.Tests.ps1 +++ b/Tests/xComputermanagement.Tests.ps1 @@ -91,7 +91,7 @@ InModuleScope MSFT_xComputer { It 'Should return a hashtable containing Name,DomainName, Credential, UnjoinCredential and WorkGroupName' { $Result = Get-TargetResource -Name $env:COMPUTERNAME $Result.GetType().Fullname | Should Be 'System.Collections.Hashtable' - $Result.Keys | Should Be @('Name','DomainName','Credential','UnjoinCredential','WorkGroupName') + $Result.Keys | Should Be @('Name','DomainName', 'JoinOU', 'CurrentOU', 'Credential','UnjoinCredential','WorkGroupName') } } Context Set-TargetResource { From 0b390536b982fa9eb3a3f4fb3b1467a998519f2d Mon Sep 17 00:00:00 2001 From: prahlm93 Date: Tue, 20 Oct 2015 12:45:19 -0400 Subject: [PATCH 06/19] Fix file encoding --- .../MSFT_xComputer/MSFT_xComputer.schema.mof | Bin 788 -> 393 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/DSCResources/MSFT_xComputer/MSFT_xComputer.schema.mof b/DSCResources/MSFT_xComputer/MSFT_xComputer.schema.mof index ddf833ff1c7fd85f39e6f410c3e937a0278ff32d..44bc6b9763019a6519b04eed6c7b62d1de8f7342 100644 GIT binary patch literal 393 zcmb79%?g4*5WWk(!{SLHqONtzekib@vJMfkxkGH}Y|O4yMDN~erl$@K%w@j${&r!? zwcY?}snGYj?M~aS7qr-zB%nwibDn|k-9wdKa|7fBd)G+{5{p*j^`Qn>k1e9oJoZc*l6Yc;V86QGNE)b-p~|?#-}p>PT*O~40T(qj%!vR^gO5y-T_&XRYgP4S4d2Xw BfP4S| literal 788 zcmchV%}WAN6vfXv=zn;)Dv+pc?HV-UW=(GBX=n#ADva zymQXI=ic}A*-@m4Vl5bL4V1Dbn#t=#C0*!D=X{&Bq*ImUR0EZO_3Fc2>kj^uvoYS# zn{k?JrDf1F*0YXvq~32Nr-mNTdDKe*!|9SJO)z!tuS0eN-J`ZZdqwmfdsBQ5vjc6T zqcQ*2L~|gQAxp0zr=JY3GWgeku{`sfO7Icm)c=Wp3*Wd+wUmvU5;3NF`KVFwXZIcl zMciG^WmTzk7i^zla~+mBk6Eoo){$MMBitHlqn&`7aBtmlbYs6>MaZm&|Hz|-kI}Y{ Zhvk&7>=QaEFXV>VUeP?$)sJnLz5%x}f_VS{ From 91923b17bca8c69189ed0901e19b5091ec703369 Mon Sep 17 00:00:00 2001 From: prahlm93 Date: Tue, 20 Oct 2015 14:43:10 -0400 Subject: [PATCH 07/19] Small fix on the test --- Tests/xComputermanagement.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/xComputermanagement.Tests.ps1 b/Tests/xComputermanagement.Tests.ps1 index 8822dd3f..1e05ff1b 100644 --- a/Tests/xComputermanagement.Tests.ps1 +++ b/Tests/xComputermanagement.Tests.ps1 @@ -88,7 +88,7 @@ InModuleScope MSFT_xComputer { It 'should not throw' { {Get-TargetResource -Name $env:COMPUTERNAME} | Should Not Throw } - It 'Should return a hashtable containing Name,DomainName, Credential, UnjoinCredential and WorkGroupName' { + It 'Should return a hashtable containing Name,DomainName, JoinOU, CurrentOU, Credential, UnjoinCredential and WorkGroupName' { $Result = Get-TargetResource -Name $env:COMPUTERNAME $Result.GetType().Fullname | Should Be 'System.Collections.Hashtable' $Result.Keys | Should Be @('Name','DomainName', 'JoinOU', 'CurrentOU', 'Credential','UnjoinCredential','WorkGroupName') From ec2135e8c91b08d66ba09898810e86748799b8dc Mon Sep 17 00:00:00 2001 From: prahlm93 Date: Tue, 20 Oct 2015 14:43:23 -0400 Subject: [PATCH 08/19] Changed function name to Verb-Noun --- DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 b/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 index b71f2233..d1967f00 100644 --- a/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 +++ b/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 @@ -29,7 +29,7 @@ function Get-TargetResource Name = $env:COMPUTERNAME DomainName = GetComputerDomain JoinOU = $JoinOU - CurrentOU = GetComputerOU + CurrentOU = Get-ComputerOU Credential = [ciminstance]$convertToCimCredential UnjoinCredential = [ciminstance]$convertToCimUnjoinCredential WorkGroupName= (gwmi WIN32_ComputerSystem).WorkGroup @@ -265,7 +265,7 @@ function GetComputerDomain } } -function GetComputerOU +function Get-ComputerOU { $ou = $null From 3fa99a6de2626905a6cc887978cf7f95c37e2d9b Mon Sep 17 00:00:00 2001 From: prahlm93 Date: Tue, 20 Oct 2015 14:47:08 -0400 Subject: [PATCH 09/19] Small spacing fix in the tests --- Tests/xComputermanagement.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/xComputermanagement.Tests.ps1 b/Tests/xComputermanagement.Tests.ps1 index 1e05ff1b..38db51be 100644 --- a/Tests/xComputermanagement.Tests.ps1 +++ b/Tests/xComputermanagement.Tests.ps1 @@ -88,10 +88,10 @@ InModuleScope MSFT_xComputer { It 'should not throw' { {Get-TargetResource -Name $env:COMPUTERNAME} | Should Not Throw } - It 'Should return a hashtable containing Name,DomainName, JoinOU, CurrentOU, Credential, UnjoinCredential and WorkGroupName' { + It 'Should return a hashtable containing Name, DomainName, JoinOU, CurrentOU, Credential, UnjoinCredential and WorkGroupName' { $Result = Get-TargetResource -Name $env:COMPUTERNAME $Result.GetType().Fullname | Should Be 'System.Collections.Hashtable' - $Result.Keys | Should Be @('Name','DomainName', 'JoinOU', 'CurrentOU', 'Credential','UnjoinCredential','WorkGroupName') + $Result.Keys | Should Be @('Name', 'DomainName', 'JoinOU', 'CurrentOU', 'Credential', 'UnjoinCredential', 'WorkGroupName') } } Context Set-TargetResource { From ce84cfa0bdd185e684f68d5277a94cd11682d212 Mon Sep 17 00:00:00 2001 From: prahlm93 Date: Tue, 20 Oct 2015 15:23:46 -0400 Subject: [PATCH 10/19] Added a few tests for Set --- Tests/xComputermanagement.Tests.ps1 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Tests/xComputermanagement.Tests.ps1 b/Tests/xComputermanagement.Tests.ps1 index 38db51be..e6b1ce14 100644 --- a/Tests/xComputermanagement.Tests.ps1 +++ b/Tests/xComputermanagement.Tests.ps1 @@ -115,6 +115,14 @@ InModuleScope MSFT_xComputer { Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName} Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName} } + It 'Changes ComputerName and changes Domain to new Domain with specified OU' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} + Set-TargetResource -Name $NotComputerName -DomainName 'adventure-works.com' -JoinOU 'OU=Computers,DC=contoso,DC=com' -Credential $Credential -UnjoinCredential $Credential | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName} + } It 'Changes ComputerName and changes Domain to Workgroup' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} Mock GetComputerDomain {'contoso.com'} @@ -148,6 +156,15 @@ InModuleScope MSFT_xComputer { Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$NewName} Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName} } + It 'Changes only the Domain to new Domain with specified OU' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} + Mock GetComputerDomain {'contoso.com'} + Set-TargetResource -Name $Env:ComputerName -DomainName 'adventure-works.com' -JoinOU 'OU=Computers,DC=contoso,DC=com' -Credential $Credential -UnjoinCredential $Credential | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$NewName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName} + } It 'Changes only Domain to Workgroup' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso.com';Workgroup='Contoso.com';PartOfDomain=$true}} Mock GetComputerDomain {''} From 8785de74239e58cc6a09dfde43c548a2ae4ad525 Mon Sep 17 00:00:00 2001 From: prahlm93 Date: Tue, 20 Oct 2015 15:28:53 -0400 Subject: [PATCH 11/19] Another add to the Set tests --- Tests/xComputermanagement.Tests.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/xComputermanagement.Tests.ps1 b/Tests/xComputermanagement.Tests.ps1 index e6b1ce14..b1649086 100644 --- a/Tests/xComputermanagement.Tests.ps1 +++ b/Tests/xComputermanagement.Tests.ps1 @@ -139,6 +139,14 @@ InModuleScope MSFT_xComputer { Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName} Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName} } + It 'Changes ComputerName and changes Workgroup to Domain with specified OU' { + Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} + Mock GetComputerDomain {''} + Set-TargetResource -Name $NotComputerName -DomainName 'Contoso.com' -JoinOU 'OU=Computers,DC=contoso,DC=com' -Credential $Credential | Should BeNullOrEmpty + Assert-MockCalled -CommandName Rename-Computer -Exactly 0 -Scope It + Assert-MockCalled -CommandName Add-Computer -Exactly 1 -Scope It -ParameterFilter {$DomainName -and $NewName} + Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It -ParameterFilter {$WorkGroupName} + } It 'Changes ComputerName and changes Workgroup to new Workgroup' { Mock Get-WMIObject {[PSCustomObject]@{Domain = 'Contoso';Workgroup='Contoso';PartOfDomain=$false}} Mock GetComputerDomain {''} From 90580c5bc43f132e356b4685f75c48d82a59c479 Mon Sep 17 00:00:00 2001 From: dcrreynolds Date: Fri, 13 Nov 2015 17:43:32 -0800 Subject: [PATCH 12/19] Enhancement #15: Name validation added. Added validation for name length and illegal characters. Includes new test cases for same. --- .../MSFT_xComputer/MSFT_xComputer.psm1 | 8 ++++++++ Tests/xComputermanagement.Tests.ps1 | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 b/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 index 92056ffd..adca71e7 100644 --- a/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 +++ b/DSCResources/MSFT_xComputer/MSFT_xComputer.psm1 @@ -9,6 +9,8 @@ function Get-TargetResource param ( [parameter(Mandatory)] + [ValidateLength(1,15)] + [ValidateScript({$_ -inotmatch'[\/\\:*?"<>|]' })] [string] $Name, [string] $DomainName, @@ -39,6 +41,8 @@ function Set-TargetResource param ( [parameter(Mandatory)] + [ValidateLength(1,15)] + [ValidateScript({$_ -inotmatch'[\/\\:*?"<>|]' })] [string] $Name, [string] $DomainName, @@ -181,6 +185,8 @@ function Test-TargetResource param ( [parameter(Mandatory)] + [ValidateLength(1,15)] + [ValidateScript({$_ -inotmatch'[\/\\:*?"<>|]' })] [string] $Name, [PSCredential]$Credential, @@ -191,6 +197,8 @@ function Test-TargetResource [string] $WorkGroupName ) + + Write-Verbose -Message "Validate desired Name is a valid name" Write-Verbose -Message "Checking if computer name is $Name" if ($Name -ne $env:COMPUTERNAME) {return $false} diff --git a/Tests/xComputermanagement.Tests.ps1 b/Tests/xComputermanagement.Tests.ps1 index 5166519e..f9213f9b 100644 --- a/Tests/xComputermanagement.Tests.ps1 +++ b/Tests/xComputermanagement.Tests.ps1 @@ -82,6 +82,12 @@ InModuleScope MSFT_xComputer { Mock GetComputerDomain {'contoso.com'} Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'Contoso' -Credential $Credential -UnjoinCredential $Credential | Should Be $false } + It 'Throws if name is to long' { + {Test-TargetResource -Name "ThisNameIsTooLong"} | Should Throw + } + It 'Throws if name contains illigal characters' { + {Test-TargetResource -Name "ThisIsBad<>"} | Should Throw + } } Context Get-TargetResource { @@ -93,6 +99,12 @@ InModuleScope MSFT_xComputer { $Result.GetType().Fullname | Should Be 'System.Collections.Hashtable' $Result.Keys | Should Be @('Name','DomainName','Credential','UnjoinCredential','WorkGroupName') } + It 'Throws if name is to long' { + {Get-TargetResource -Name "ThisNameIsTooLong"} | Should Throw + } + It 'Throws if name contains illigal characters' { + {Get-TargetResource -Name "ThisIsBad<>"} | Should Throw + } } Context Set-TargetResource { Mock Rename-Computer {} @@ -171,6 +183,12 @@ InModuleScope MSFT_xComputer { Assert-MockCalled -CommandName Rename-Computer -Exactly 1 -Scope It Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It } + It 'Throws if name is to long' { + {Set-TargetResource -Name "ThisNameIsTooLong"} | Should Throw + } + It 'Throws if name contains illigal characters' { + {Set-TargetResource -Name "ThisIsBad<>"} | Should Throw + } } } } From aa47e4d59094567689b766eb07ad5c45fa3b2694 Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Mon, 7 Dec 2015 16:48:49 -0800 Subject: [PATCH 13/19] Replacing before_deploy with deploy_script --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 599bd19a..5f39cdbb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,7 +34,7 @@ test_script: #---------------------------------# # scripts to run before deployment -before_deploy: +deploy_script: - ps: | # Creating project artifact $stagingDirectory = (Resolve-Path ..).Path From 7fe0e4af65fd0a5851dbeecf48671037c336f976 Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Wed, 16 Dec 2015 15:22:14 -0800 Subject: [PATCH 14/19] Temporary workaround for pester issue causing build to get stuck --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 5f39cdbb..2b96e539 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ #---------------------------------# version: 1.3.{build}.0 install: - - cinst -y pester + - cinst -y pester --version 3.3.13 - git clone https://github.com/PowerShell/DscResource.Tests - ps: Push-Location - cd DscResource.Tests From cab43e89ae47e252dba7de4c98c05921a3c3517e Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Thu, 7 Jan 2016 10:17:27 -0800 Subject: [PATCH 15/19] Reverting temporary workaround for pester issue causing build to get stuck --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 2b96e539..5f39cdbb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ #---------------------------------# version: 1.3.{build}.0 install: - - cinst -y pester --version 3.3.13 + - cinst -y pester - git clone https://github.com/PowerShell/DscResource.Tests - ps: Push-Location - cd DscResource.Tests From 4404ddf90dd998d17d7dc2195c3b5217fd8448fd Mon Sep 17 00:00:00 2001 From: KarolKaczmarek Date: Tue, 2 Feb 2016 11:24:53 -0800 Subject: [PATCH 16/19] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 8d3cf9db..d7aa9bbe 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ xComputer resource has following properties: ## Versions - ### 1.3.0 * xComputer From c9f7bd82f7fba5bc1b610b9a414ceb6d2a16698f Mon Sep 17 00:00:00 2001 From: KarolKaczmarek Date: Tue, 2 Feb 2016 11:25:38 -0800 Subject: [PATCH 17/19] Update xComputerManagement.psd1 --- xComputerManagement.psd1 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xComputerManagement.psd1 b/xComputerManagement.psd1 index cd643fdf..138608af 100644 --- a/xComputerManagement.psd1 +++ b/xComputerManagement.psd1 @@ -30,5 +30,29 @@ FunctionsToExport = '*' # Cmdlets to export from this module CmdletsToExport = '*' + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource') + + # A URL to the license for this module. + LicenseUri = 'https://github.com/PowerShell/xComputerManagement/blob/master/LICENSE' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/PowerShell/xComputerManagement' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # End of PSData hashtable + +} # End of PrivateData hashtable } From a7b8c0ad63438e62f1a6269f457737d686b5a430 Mon Sep 17 00:00:00 2001 From: KarolKaczmarek Date: Tue, 2 Feb 2016 13:45:28 -0800 Subject: [PATCH 18/19] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d7aa9bbe..ac75046c 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,9 @@ xComputer resource has following properties: ## Versions +### Unreleased +* Adding Name parameter validation + ### 1.3.0 * xComputer From d8153dc45dd1e4c6cd14b495d2196dc67c53f296 Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Tue, 2 Feb 2016 13:53:39 -0800 Subject: [PATCH 19/19] Releasing version 1.4.0.0 --- README.md | 2 ++ appveyor.yml | 4 ++-- xComputerManagement.psd1 | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ac75046c..abb8b8e1 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ xComputer resource has following properties: ## Versions ### Unreleased + +### 1.4.0.0 * Adding Name parameter validation ### 1.3.0 diff --git a/appveyor.yml b/appveyor.yml index 5f39cdbb..bbb2b1b5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ #---------------------------------# # environment configuration # #---------------------------------# -version: 1.3.{build}.0 +version: 1.4.{build}.0 install: - cinst -y pester - git clone https://github.com/PowerShell/DscResource.Tests @@ -39,7 +39,7 @@ deploy_script: # Creating project artifact $stagingDirectory = (Resolve-Path ..).Path $manifest = Join-Path $pwd "xComputerManagement.psd1" - (Get-Content $manifest -Raw).Replace("1.3.0", $env:APPVEYOR_BUILD_VERSION) | Out-File $manifest + (Get-Content $manifest -Raw).Replace("1.4.0.0", $env:APPVEYOR_BUILD_VERSION) | Out-File $manifest $zipFilePath = Join-Path $stagingDirectory "$(Split-Path $pwd -Leaf).zip" Add-Type -assemblyname System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::CreateFromDirectory($pwd, $zipFilePath) diff --git a/xComputerManagement.psd1 b/xComputerManagement.psd1 index 138608af..e5889eb6 100644 --- a/xComputerManagement.psd1 +++ b/xComputerManagement.psd1 @@ -1,6 +1,6 @@ @{ # Version number of this module. -ModuleVersion = '1.3.0' +ModuleVersion = '1.4.0.0' # ID used to uniquely identify this module GUID = 'B5004952-489E-43EA-999C-F16A25355B89'