We daily run a Powershell script (v1.0) that checks server health and produce a report in .xls format. The report name is dynamic in nature as it contains the date and time stamp of the execution time (for example, "MorningCheck_<date>_<time>
" i.e., "MorningCheck_16email@example.com
The report gets automatically stored into the server's local drive - "C:\MorningCheck
I have also created a mapped drive (Y:) to map a shared network location -
"Y:\Server Health Check\MorningCheckReport
I want a script with the following features -
It will pick-up the most updated Report (.xls) file from -
It will then create month-wise folder in the network share drive. For example, "Y:\Server Health Chek\MorningCheckReport\September2013"
Copy that most updated Report (.xls file) from "C:\MorningCheck" to the respective month-wise folder -
"Y:\Server Health Check\MorningCheckReport\MorningCheck_<date>_<time>.xls"
I have created following script to meet my above requirements but unable to copy the file into the shared location. Please help me out to resolve this issue.
# Creating Month-wise folder
$SubFolderNameMonth = Get-Date -Format MMMM
$SubFolderNameYear = Get-Date -Format yyyy
$SubFolderNameFull = SubFolderNameMonth + "SubFolderNameYear"
$Location_Y = "Y:\Server Health Chek\MorningCheckReport"
New-Item -Path $Location_Y -Name $SubFolderNameFull -ItemType "directory"
# Select the most updated report
$Report = (GCI C:\MorningCheck | sort LastWriteTime -Descending | Select -First 1).Full
# Copy the updated Report to the shared network path
Copy $Report "Y:\Server Health Chek\MorningCheckReport" + "\" + $$SubFolderNameFull