From f414a1f512c16185d56c0b9e6f0b04f908b80a37 Mon Sep 17 00:00:00 2001 From: Arturas Kuznecovas Date: Tue, 14 Jun 2016 00:01:28 +0300 Subject: [PATCH 1/7] * Added ExcludeDirs parameter to Get-TargetResource, Set-TargetResource, Test-TargetResource and Get-RobocopyArguments functions; * Internal calls to Get-RobocopyArguments now use Splatting @psBoundParameters; --- .../MSFT_xRobocopy/MSFT_xRobocopy.psm1 | 18 +++++++++++++++--- .../MSFT_xRobocopy/MSFT_xRobocopy.schema.mof | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 b/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 index 2b4df64..0373d76 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')) { @@ -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[]; From 8e7319cf255b41e99f14e04a252ab92461089b3e Mon Sep 17 00:00:00 2001 From: Arturas Kuznecovas Date: Tue, 14 Jun 2016 00:02:59 +0300 Subject: [PATCH 2/7] Added additional examples to illustrate AdditionalArgs usage; --- Examples/xRobocopy.SimpleCopyOptions.ps1 | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Examples/xRobocopy.SimpleCopyOptions.ps1 b/Examples/xRobocopy.SimpleCopyOptions.ps1 index e498bae..1edcb14 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 ExludeFiles option + xRobocopy ExludeSingleFile + { + Source = 'C:\temp\source' + Destination = 'C:\temp\destination' + ExcludeFiles = 'file.jpg' + } + + #this will exclude multiple file patterns using AdditionalArgs option + xRobocopy ExludeSingleFile + { + Source = 'C:\temp\source' + Destination = 'C:\temp\destination' + AdditionalArgs = @('/XF', 'file1.JPG', 'file2.JPG') + } + + #this will exclude single directory pattern using ExludeDirs option + xRobocopy ExludeSingleDirectory + { + Source = 'C:\temp\source' + Destination = 'C:\temp\destination' + SubdirectoriesIncludingEmpty = $true + ExcludeDirs = 'Dir1' + } + + #this will exclude multiple directory patterns using AdditionalArgs option + xRobocopy ExludeSingleDirectory + { + Source = 'C:\temp\source' + Destination = 'C:\temp\destination' + SubdirectoriesIncludingEmpty = $true + AdditionalArgs = @('/XD', 'Dir1', 'Dir2') + } #> } } From 8861ca267d4afb34abce4919147187caae169e91 Mon Sep 17 00:00:00 2001 From: Arturas Kuznecovas Date: Tue, 14 Jun 2016 00:04:42 +0300 Subject: [PATCH 3/7] Updated Resource documentation with ExcludeDirs parameter; Updated unreleased section; --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d3ba370..b36947b 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,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. @@ -73,8 +74,11 @@ We reserve resource and module names without prefixes ("x" or "c") for future us ## Versions -### Unreleased - +### Unreleased + +* Added ExcludeDirs parameter +* Added additional examples + ### 2.0.0.0 * Improved Test-TargetResource method to run robocopy with the same parameters as in Set-TargetResource From 8cb387f9aa2725576fb058a2cddec0e3b64869e5 Mon Sep 17 00:00:00 2001 From: Arturas Kuznecovas Date: Tue, 14 Jun 2016 00:06:00 +0300 Subject: [PATCH 4/7] Fixed line endings --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b36947b..93b273f 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ We reserve resource and module names without prefixes ("x" or "c") for future us ### Unreleased -* Added ExcludeDirs parameter +* Added ExcludeDirs parameter * Added additional examples ### 2.0.0.0 From 780a12cc9b3e9c0a96d6514c7107861cdc0452ad Mon Sep 17 00:00:00 2001 From: Arturas Kuznecovas Date: Tue, 14 Jun 2016 19:39:19 +0300 Subject: [PATCH 5/7] Added gitignore file to exclude .vscode folder; --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore 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 From 83f2bca28c0df07c58576226748d97ebb4b2db69 Mon Sep 17 00:00:00 2001 From: Arturas Kuznecovas Date: Fri, 5 Aug 2016 00:33:35 +0300 Subject: [PATCH 6/7] Fixed typos --- DSCResource.Tests | 1 + Examples/xRobocopy.SimpleCopyOptions.ps1 | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 160000 DSCResource.Tests 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/Examples/xRobocopy.SimpleCopyOptions.ps1 b/Examples/xRobocopy.SimpleCopyOptions.ps1 index 1edcb14..bb7b3e3 100644 --- a/Examples/xRobocopy.SimpleCopyOptions.ps1 +++ b/Examples/xRobocopy.SimpleCopyOptions.ps1 @@ -46,8 +46,8 @@ configuration RobocopyExample AdditionalArgs = '/mir' } - #this will exclude single file pattern using ExludeFiles option - xRobocopy ExludeSingleFile + #this will exclude single file pattern using ExcludeFiles option + xRobocopy ExcludeSingleFile { Source = 'C:\temp\source' Destination = 'C:\temp\destination' @@ -55,15 +55,15 @@ configuration RobocopyExample } #this will exclude multiple file patterns using AdditionalArgs option - xRobocopy ExludeSingleFile + xRobocopy ExcludeSingleFile { Source = 'C:\temp\source' Destination = 'C:\temp\destination' AdditionalArgs = @('/XF', 'file1.JPG', 'file2.JPG') } - #this will exclude single directory pattern using ExludeDirs option - xRobocopy ExludeSingleDirectory + #this will exclude single directory pattern using ExcludeDirs option + xRobocopy ExcludeSingleDirectory { Source = 'C:\temp\source' Destination = 'C:\temp\destination' @@ -72,7 +72,7 @@ configuration RobocopyExample } #this will exclude multiple directory patterns using AdditionalArgs option - xRobocopy ExludeSingleDirectory + xRobocopy ExcludeSingleDirectory { Source = 'C:\temp\source' Destination = 'C:\temp\destination' From 706e8e1f90274fc2f768eb6cbe149d75c36ceab3 Mon Sep 17 00:00:00 2001 From: Arturas Kuznecovas Date: Fri, 5 Aug 2016 00:39:38 +0300 Subject: [PATCH 7/7] Fixed bug in Test-TargetResource to return $LASTEXITCODE if error occurred --- DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 b/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 index 0373d76..1958935 100644 --- a/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 +++ b/DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1 @@ -206,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