Hi, I want to copy files/folders recurse and with it copy also all ACLs. When i run the script it gaves me the following error. Any idea what am i doing wrong here?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | try {$Files = Get-ChildItem -Path $Source -Recurse -ErrorAction Stop$C = $Files.countif ($Files){ foreach ($Filein$Files) {try{$File | Copy-Item -Destination $Destination -ErrorAction stop -Verbose$ACL = Get-Acl $File.FullName -ErrorAction stop -Verbose Set-Acl -Path ($File.FullName).Replace($Source,$Destination) -AclObject $ACL -ErrorAction stop -Verbose }catch{ write-warning "Error! $($file.Fullname)" Write-error $_ } } } else { Write-Warning "No files to move" } } Catch{ $ErrorMessage = $_.Exception.Message |
The Error message is below:
1 2 3 4 5 6 7 8 9 10 | VERBOSE: Performing the operation "Copy File" on target "Item: C:\utdelat\A\Capsules\PinBoard\se0801.cpsx Destination: C:\utdelat\c\se0801.cpsx". WARNING:Error! C:\utdelat\A\Capsules\PinBoard\se0801.cpsx Copy-FilesACL : System.Management.Automation.ItemNotFoundException: Cannot find path 'C:\utdelat\c\PinBoard\se0801.cpsx' because it does not exist. at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider provider, CmdletProviderContext context) at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider& providerInstance) at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider& providerInstance) at System.Management.Automation.PathIntrinsics.GetResolvedPSPathFromPSPath(String path, CmdletProviderContext context) at Microsoft.PowerShell.Commands.SetAclCommand.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() At C:\Git\MoveFiles\Move-ACL.ps1:85char:1 |