Question Details

No question body available.

Tags

arrays windows powershell exclude-constraint

Answers (1)

Accepted Answer Available
Accepted Answer
May 27, 2026 Score: 3 Rep: 466 Quality: High Completeness: 80%

The main issue is '/XF ".lnk"'; that would need to be two separate arguments: @('/XF', '.lnk')

And you're nearly there with the splatting; but there's no need to combine the arrays.
You can use multiple splat arrays, and you can mix and match them with regular command line options, so like this, for example:

$directorySource = 'C:\Files'
$directoryTarget = 'C:\Temp\Files'
$LogPath = 'C:\Temp\robocopy.log'

$robocopyBaseArguments = @( '/S', # Copy subdirectories, exclude empty subdirectories '/ZB', # Copies files in restartable mode, switches to backup mode if access denied '/COPY:DT', # Copies Data and Time stamp file properties '/XA:SHT', # Excludes System, Hidden, and Temp files '/W:1', # Wait 1 second between retries '/R:2' # Retry 2 times '/NP' # No Progress; doesn't play well with the log file )

$robocopyExcludedExtensions = @( '/XF' '*.lnk' )

/L: Log only (test mode) instead of actually copying while still testing

/TEE: Log and write to console while testing

& robocopy.exe $directorySource $directoryTarget /L /TEE @robocopyBaseArguments @robocopyExcludedExtensions /LOG+:$LogPath