samiam41
asked on
Save log file with the name of yesterday's date - Powershell
Experts, here is a script that outputs the info to a log file but I need the filename to include yesterday's date. I've tried a few things in the attempt to learn on my own but haven't had much luck. Looking for some help.
format MMddYYYY
Thanks Experts!
$ServerList = @'
"Name", "Path"
servers
'@ | ConvertFrom-Csv
$Pattern = (Get-Date).AddDays(-1).ToString('MM\/dd\/yyyy') + ' * --- SCHEDULEREC STATUS BEGIN*'
$in = $false
$ServerList | ForEach-Object {
$Server = $_
"========== $($Server.Name) ============================================================"
Try {
Switch -Wildcard (Get-Content -Path "\\$($Server.Name)\$($Server.Path.Replace(':', '$'))" -ErrorAction Stop) {
$Pattern {$in = $true}
'*SCHEDULEREC STATUS END*' {$in = $false}
default {If ($in) {$_}}
}
} Catch {
"ERROR accessing '$($Server.Path)': $($_.Exception.Message)"
}
} | Set-Content -Path \\w2k12FS01\PUBLIC\Tivoli_Master_Logs\Combined[yesterdaysdate].log
format MMddYYYY
Thanks Experts!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Dustin, thank you for the links. It should give me some more insight into PS.