Hi all,
I have a real strange one here. I have a script that simply copies some files from one location to a number of other subsequent locations. The first time I run the script everything works as expected but if I run it again it creates an additional folder and I do not understand why? It seems Copy-Item works as intended the first time (to copy the contents of a folder to a destination) but if I run it a second time it copies the folder object itself too?
[pre]
$Path = ‘C:\Users\Public\Solibri\SMC*’
$ScriptLocation = (Split-Path $MyInvocation.MyCommand.Path) #Get location of running script
if (Test-Path $Path.Trim()) {
$Destination = Get-ChildItem $Path | Select-Object -ExpandProperty FullName #Get the fullname of the wildcard folders
$Destination | ForEach-Object {
$_ += '\RuleSets\FolderToCopy' #Add additional directories to $Destination
Copy-Item $ScriptLocation\FolderToCopy $_ -Recurse -Force -ErrorAction Stop #Make
}
}
[/pre]
Thanks for any help you can provide - I have had 3 people look at this so far and cannot work it out.