Creation symbolic link daily files

Copper Contributor

Hello

For application needs I create a daily symbolic link with the same naming convention.

1) Deletion of the last symbolic link type file at the destination
Creation of a symbolic type file at the destination by referring to the file that was created the same day at the source.

In this example the source file starts with the date and time followed by the file name "yyyy_MM_dd_HH_mm_ss_filereport.xls (2021_02_16_10_10_10_filereport.xls).

When the symbolic link is created, it is created without the start date (filereport.xls ".Symlink")

The script below works correctly.

However, I can't do the same thing, when I have several daily files with different names but always starting with the date and time. Anyone have an idea how I can do the same on all the differently named log files?

 

$Fichiers = Get-Childitem "$Source*.xls" -Recurse | where { $_.CreationTime -gt (Get-Date).AddHours(-2.5)}
$Source = "\\share\report\"
$Destination = "\\Share\Report\Dayly\"
$DailyLog = $Fichiers
$Localhost = $Destination + "filereport.xls"

write-host $Source
write-host $DailyLog

pushd $Destination

if (Test-Path $DailyLog -ErrorAction SilentlyContinue) {

if (Test-Path $Localhost -ErrorAction SilentlyContinue) {
remove-item $Localhost -Confirm:$false -Force
Start-Sleep -Seconds 3
}

New-item -ItemType SymbolicLink -Path $Destination -Name ".\filereport.xls" -Value $DailyLog
}

gci | ? { $_.LinkType } | Select FullName, LinkType, Target
popd

 

 

0 Replies