Creation symbolic link daily files

%3CLINGO-SUB%20id%3D%22lingo-sub-2141620%22%20slang%3D%22en-US%22%3ECreation%20symbolic%20link%20daily%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2141620%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3C%2FP%3E%3CP%3EFor%20application%20needs%20I%20create%20a%20daily%20symbolic%20link%20with%20the%20same%20naming%20convention.%3C%2FP%3E%3CP%3E1)%20Deletion%20of%20the%20last%20symbolic%20link%20type%20file%20at%20the%20destination%3CBR%20%2F%3ECreation%20of%20a%20symbolic%20type%20file%20at%20the%20destination%20by%20referring%20to%20the%20file%20that%20was%20created%20the%20same%20day%20at%20the%20source.%3C%2FP%3E%3CP%3EIn%20this%20example%20the%20source%20file%20starts%20with%20the%20date%20and%20time%20followed%20by%20the%20file%20name%20%22yyyy_MM_dd_HH_mm_ss_filereport.xls%20(2021_02_16_10_10_10_filereport.xls).%3C%2FP%3E%3CP%3EWhen%20the%20symbolic%20link%20is%20created%2C%20it%20is%20created%20without%20the%20start%20date%20(filereport.xls%20%22.Symlink%22)%3C%2FP%3E%3CP%3EThe%20script%20below%20works%20correctly.%3C%2FP%3E%3CP%3EHowever%2C%20I%20can't%20do%20the%20same%20thing%2C%20when%20I%20have%20several%20daily%20files%20with%20different%20names%20but%20always%20starting%20with%20the%20date%20and%20time.%20Anyone%20have%20an%20idea%20how%20I%20can%20do%20the%20same%20on%20all%20the%20differently%20named%20log%20files%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24Fichiers%20%3D%20Get-Childitem%20%22%24Source*.xls%22%20-Recurse%20%7C%20where%20%7B%20%24_.CreationTime%20-gt%20(Get-Date).AddHours(-2.5)%7D%3CBR%20%2F%3E%24Source%20%3D%20%22%5C%5Cshare%5Creport%5C%22%3CBR%20%2F%3E%24Destination%20%3D%20%22%5C%5CShare%5CReport%5CDayly%5C%22%3CBR%20%2F%3E%24DailyLog%20%3D%20%24Fichiers%3CBR%20%2F%3E%24Localhost%20%3D%20%24Destination%20%2B%20%22filereport.xls%22%3C%2FP%3E%3CP%3Ewrite-host%20%24Source%3CBR%20%2F%3Ewrite-host%20%24DailyLog%3C%2FP%3E%3CP%3Epushd%20%24Destination%3C%2FP%3E%3CP%3Eif%20(Test-Path%20%24DailyLog%20-ErrorAction%20SilentlyContinue)%20%7B%3C%2FP%3E%3CP%3Eif%20(Test-Path%20%24Localhost%20-ErrorAction%20SilentlyContinue)%20%7B%3CBR%20%2F%3Eremove-item%20%24Localhost%20-Confirm%3A%24false%20-Force%3CBR%20%2F%3EStart-Sleep%20-Seconds%203%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3ENew-item%20-ItemType%20SymbolicLink%20-Path%20%24Destination%20-Name%20%22.%5Cfilereport.xls%22%20-Value%20%24DailyLog%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3Egci%20%7C%20%3F%20%7B%20%24_.LinkType%20%7D%20%7C%20Select%20FullName%2C%20LinkType%2C%20Target%3CBR%20%2F%3Epopd%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

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