Back
Powershell Script

Author: admin 03/24/2021
Language: PowerShell


Description:

Here is a simple script that I use to copy and rename my daily reports.

Article:

$MonthNumber = get-date -Format MM
$DayNumber = get-date -Format dd
$Month = ""
$Year = get-date -Format yyyy
$ServerFolder = "\\0.0.0.0\Daily Reports\"
$TemplateFilePath = '\\0.0.0.0\Department\DailyReportsTemplate.docx'
$TemplateFilePath2 = 'C:\Users\user\Desktop\AM.docx'

#Loop Month array
$MonthNumber = $MonthNumber.TrimStart('0')
$data = @('1 Jan','2 Feb','3 Mar','4 April','5 May','6 June','7 July','8 Aug','9 Sept','10 Oct','11 Nov','12 Dec')
for ( $index = 0; $index -lt $data.count; $index++)
{
    if ($MonthNumber -eq ($index + 1)){$Month = $data[$index]}
}

#Copy and Rename Daily Report
$ACReportPath = $ServerFolder + $Year + '\' + $Month + '\' + "Department\"
$NewFile = $ACReportPath + 'DailyReports ' + $DayNumber + '.docx'

$FileExists = Test-Path $NewFile
If ($FileExists -eq $False) {
    Copy-Item $TemplateFilePath $NewFile
}
Else {Write-Host "File already at this location"}

#Copy and Rename AM Report
$ACReportPath2 = $ServerFolder + $Year + '\' + $Month + '\' + "Department\"
$NewFile2 = $ACReportPath2 + 'AM ' + $DayNumber + '.docx'

$FileExists2 = Test-Path $NewFile2
If ($FileExists2 -eq $False) {
    Copy-Item $TemplateFilePath2 $NewFile2
}
Else {Write-Host "File already at this location"}


Back
Comments
Add Comment
There are no comments yet.