Hi, I’m making a script that in theory should be simple, but apparently is more complex than that.
I have a folder (source) with some xml files, hal of them have a name that begins with “030”, the other half begins with “150”. I have to select the last edited file whose name beins with “030” and copy it to another folder (destination).
My first idea was cicle through every file and if it contains “030” in the name add it to an array (Brescia), next I would check the file in that array with the LastWrite Time and copy it’s path.
However when I chekc filePath i get the path of my .ps1 file, so something must be off
$send = "C:\Source"
$receive = "C:\Destination"
$Brescia =@()
$search_results = Get-ChildItem -Path $send | Where-Object { ((! $_.PSIsContainer))}
foreach ($file in $search_results) {
if($file.Name -match "030"){
$Brescia + $file
}
}
$lastfile = gci $Brescia | sort LastWriteTime | select -last 1
$filePath =$lastfile.FullName
Write-Output $filePath
Copy-Item $filepath -Destination $receive
Thank you in advance for your help