I'm trying to copy log files from a number of sources to a local folder, but nothing seems to be happening.
My code:
Param( [parameter(Mandatory=$true,ValueFromPipeline=$true)] [ValidateScript({Test-Path $_ -PathType 'Leaf'})] [String] $FileOfLogFiles ) $ListOfLogFiles = Get-Content $FileOfLogFiles $CurrentPath = Get-Location $CurrentTime = Get-Date -UFormat "%Y-%m-%d_%H-%M-%S_%Z" $DestinationPath = "$CurrentPath\$CurrentTime\" Write-Host "" ForEach ( $LineOfLogFiles in $ListOfLogFiles ) { If ( $LineOfLogFiles.substring(0,1) -eq "#" ) { } Else { [string[]]$ElementsOfLineOfLogFiles = $LineOfLogFiles.split(";") $Server = $ElementsOfLineOfLogFiles[0] $Volume = $ElementsOfLineOfLogFiles[1] $LogFolder = $ElementsOfLineOfLogFiles[2] $SourcePath = "\\$Server\$Volume`$\$LogFolder\*.log" Write-Host "$(Get-Date -Format o) SourcePath = '$SourcePath'" Write-Host "$(Get-Date -Format o) DestinationPath = '$DestinationPath'" Get-ChildItem -Path "$SourcePath" -Recurse"Copy-Item -Path `"$SourcePath`" -Destination $DestinationPath -force -recurse -verbose" Copy-Item -Path "$SourcePath" -Destination $DestinationPath -force -recurse -verbose } Write-Host "" }
My data file looks like this:
vcac2web1;e;Program Files (x86)
vcac2web2;e;Program Files (x86)
vcac2mgmt1;e;Program Files (x86)
vcac2mgmt2;e;Program Files (x86)
vcac2demw1;e;Program Files (x86)
vcac2demw2;e;Program Files (x86)
vcac2agnt1;e;Program Files (x86)
vcac2agnt2;e;Program Files (x86)
The script does not generate any errors, but no files are actually copied. The Get-ChildItem does find the log files. I am running this in PowerShell proper, not the IDE. OS = Windows Server 2012 not R2, PS = 3.0