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

Dev 18 exclude dirs2 #23

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Visual Studio Code folder
.vscode
1 change: 1 addition & 0 deletions DSCResource.Tests
Submodule DSCResource.Tests added at c845d5
20 changes: 16 additions & 4 deletions DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function Get-TargetResource
[System.String]
$ExcludeFiles,

[System.String]
$ExcludeDirs,

[System.String]
$LogOutput,

Expand All @@ -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)
{
Expand Down Expand Up @@ -103,6 +106,9 @@ function Set-TargetResource
[System.String]
$ExcludeFiles,

[System.String]
$ExcludeDirs,

[System.String]
$LogOutput,

Expand All @@ -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
Expand Down Expand Up @@ -158,6 +164,9 @@ function Test-TargetResource
[System.String]
$ExcludeFiles,

[System.String]
$ExcludeDirs,

[System.String]
$LogOutput,

Expand All @@ -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'))
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -239,6 +248,9 @@ function Get-RobocopyArguments
[System.String]
$ExcludeFiles,

[System.String]
$ExcludeDirs,

[System.String]
$LogOutput,

Expand Down
1 change: 1 addition & 0 deletions DSCResources/MSFT_xRobocopy/MSFT_xRobocopy.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
34 changes: 34 additions & 0 deletions Examples/xRobocopy.SimpleCopyOptions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
#>
}
}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down