diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9964c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Visual Studio Code folder +.vscode diff --git a/DSCResource.Tests b/DSCResource.Tests new file mode 160000 index 0000000..c845d58 --- /dev/null +++ b/DSCResource.Tests @@ -0,0 +1 @@ +Subproject commit c845d58d6b1f5f16ae2992f7b2c15e76d611281d diff --git a/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 b/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 index 2b4df64..1958935 100644 --- a/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 +++ b/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 @@ -33,6 +33,9 @@ function Get-TargetResource [System.String] $ExcludeFiles, + [System.String] + $ExcludeDirs, + [System.String] $LogOutput, @@ -43,7 +46,7 @@ function Get-TargetResource $AdditionalArgs ) - $result = Test-TargetResource $Source $Destination $Files $Retry $Wait $SubdirectoriesIncludingEmpty $Restartable $MultiThreaded $ExcludeFiles $LogOutput $AppendLog $AdditionalArgs + $result = Test-TargetResource @psBoundParameters $ensure = 'Absent' if($result -eq $true) { @@ -103,6 +106,9 @@ function Set-TargetResource [System.String] $ExcludeFiles, + [System.String] + $ExcludeDirs, + [System.String] $LogOutput, @@ -113,7 +119,7 @@ function Set-TargetResource $AdditionalArgs ) - $arguments = Get-RobocopyArguments $Source $Destination $Files $Retry $Wait $SubdirectoriesIncludingEmpty $Restartable $MultiThreaded $ExcludeFiles $LogOutput $AppendLog $AdditionalArgs + $arguments = Get-RobocopyArguments @psBoundParameters Write-Verbose "Executing robocopy.exe with: $arguments" &robocopy $arguments | Out-Null @@ -158,6 +164,9 @@ function Test-TargetResource [System.String] $ExcludeFiles, + [System.String] + $ExcludeDirs, + [System.String] $LogOutput, @@ -168,7 +177,7 @@ function Test-TargetResource $AdditionalArgs ) - $arguments = Get-RobocopyArguments $Source $Destination $Files $Retry $Wait $SubdirectoriesIncludingEmpty $Restartable $MultiThreaded $ExcludeFiles $LogOutput $AppendLog $AdditionalArgs + $arguments = Get-RobocopyArguments @psBoundParameters if(!$arguments.Contains('/L') -and !$arguments.Contains('/l')) { @@ -197,7 +206,7 @@ function Test-TargetResource } else { - throw "robocopy returned with errors! Exit code: $result! More info here:https://support.microsoft.com/en-us/kb/954404" + throw "robocopy returned with errors! Exit code: $LASTEXITCODE! More info here:https://support.microsoft.com/en-us/kb/954404" } return $result @@ -239,6 +248,9 @@ function Get-RobocopyArguments [System.String] $ExcludeFiles, + [System.String] + $ExcludeDirs, + [System.String] $LogOutput, diff --git a/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.schema.mof b/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.schema.mof index e1e278e..53c5588 100644 --- a/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.schema.mof +++ b/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.schema.mof @@ -10,6 +10,7 @@ class MSFT_xRobocopy : OMI_BaseResource [Write, Description("Copy files in restartable mode.")] Boolean Restartable; [Write, Description("Do multi-threaded copies with n threads (default 8). N must be at least 1 and not greater than 128. This option is incompatible with the /IPG and /EFSRAW options. Redirect output using /LOG option for better performance.")] Boolean MultiThreaded; [Write, Description("Exclude Files matching given names/paths/wildcards.")] String ExcludeFiles; + [Write, Description("Exclude Directories matching given names/paths/wildcards.")] String ExcludeDirs; [Write, Description("Output status to LOG file.")] String LogOutput; [Write, Description("Determine whether to overwrite log file or append.")] Boolean AppendLog; [Write, Description("Robocopy has MANY configuration options. Too many to present them all as DSC parameters effectively. Use this option to set additional parameters. Each parameter should be a separate array member. This array will be combined with main argument array. For a list of options run Robocopy /??? in a shell window.")] String AdditionalArgs[]; diff --git a/Examples/xRobocopy.SimpleCopyOptions.ps1 b/Examples/xRobocopy.SimpleCopyOptions.ps1 index e498bae..bb7b3e3 100644 --- a/Examples/xRobocopy.SimpleCopyOptions.ps1 +++ b/Examples/xRobocopy.SimpleCopyOptions.ps1 @@ -45,6 +45,40 @@ configuration RobocopyExample Destination = 'C:\temp\destination' AdditionalArgs = '/mir' } + + #this will exclude single file pattern using ExcludeFiles option + xRobocopy ExcludeSingleFile + { + Source = 'C:\temp\source' + Destination = 'C:\temp\destination' + ExcludeFiles = 'file.jpg' + } + + #this will exclude multiple file patterns using AdditionalArgs option + xRobocopy ExcludeSingleFile + { + Source = 'C:\temp\source' + Destination = 'C:\temp\destination' + AdditionalArgs = @('/XF', 'file1.JPG', 'file2.JPG') + } + + #this will exclude single directory pattern using ExcludeDirs option + xRobocopy ExcludeSingleDirectory + { + Source = 'C:\temp\source' + Destination = 'C:\temp\destination' + SubdirectoriesIncludingEmpty = $true + ExcludeDirs = 'Dir1' + } + + #this will exclude multiple directory patterns using AdditionalArgs option + xRobocopy ExcludeSingleDirectory + { + Source = 'C:\temp\source' + Destination = 'C:\temp\destination' + SubdirectoriesIncludingEmpty = $true + AdditionalArgs = @('/XD', 'Dir1', 'Dir2') + } #> } } diff --git a/README.md b/README.md index c32f90e..c665726 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Details - **Restartable**: Copy files in restartable mode. - **MultiThreaded**: Do multi-threaded copies with n threads (default 8). N must be at least 1 and not greater than 128. This option is incompatible with the /IPG and /EFSRAW options. Redirect output using /LOG option for better performance. - **ExcludeFiles**: Exclude Files matching given names/paths/wildcards. +- **ExcludeDirs**: Exclude Directories matching given names/paths/wildcards. - **LogOutput**: Output status to LOG file. - **AppendLog**: Determine whether to overwrite log file or append. - **AdditionalArgs**: Robocopy has MANY configuration options. Too many to present them all as DSC parameters effectively. Use this option to set additional parameters. Each parameter should be a separate array member. This array will be combined with main argument array. For a list of options run Robocopy /??? in a shell window. @@ -78,6 +79,8 @@ We reserve resource and module names without prefixes ("x" or "c") for future us ### Unreleased * Converted appveyor.yml to install Pester from PSGallery instead of from Chocolatey. +* Added ExcludeDirs parameter +* Added additional examples ### 2.0.0.0