I have a folder on a server that contains thousands of log files. New files are being populated every second and the folder continues to grow. Once a week I want to take those files, copy them and paste them into another folder. I will then run a python script to process the logs in the new folder. My script is processing around 70K logs a week and takes over an hour.
how can I make it more efficient/faster?
$ScriptProperties = @{
"FolderDir" = "\\server\folder1\Temp";
"FolderName" = "Orignal_Folder";
"OldFolderName" = "New_Folder";
"TempFolderName" = "Temp_Folder";
}
#$DateStamp = get-date -uformat "%Y-%m-%d@%H-%M-%S"
# if (Test-Path "$($ScriptProperties.FolderDir)\$($ScriptProperties.FolderName)"){
# #write-host "$($ScriptProperties.FolderDir)\$($ScriptProperties.FolderName) folder folder"
# Copy-Item -Path "$($ScriptProperties.FolderDir)\$($ScriptProperties.FolderName)" -Destination "$($ScriptProperties.FolderDir)\$($ScriptProperties.OldFolderName)-$($DateStamp)" -force -recurse
# #New-Item -Path "$($ScriptProperties.FolderDir)\$($ScriptProperties.FolderName)" -type directory -force
# }#else{
# #write-host "folder not found."
# New-Item -Path "$($ScriptProperties.FolderDir)\$($ScriptProperties.FolderName)" -type directory
#}
write-host "Start"
if (Test-Path "$($ScriptProperties.FolderDir)\$($ScriptProperties.FolderName)"){
#Renaming folder to Temp directory
Rename-Item "$($ScriptProperties.FolderDir)\$($ScriptProperties.FolderName)" -NewName "$($ScriptProperties.FolderDir)\$($ScriptProperties.TempFolderName)"
#Creating new Log directory
New-Item -Path "$($ScriptProperties.FolderDir)\$($ScriptProperties.FolderName)" -type directory
#Creating new Move folder if not found
if (-Not (Test-Path "$($ScriptProperties.FolderDir)\$($ScriptProperties.OldFolderName)")) {New-Item -Path "$($ScriptProperties.FolderDir)\$($ScriptProperties.OldFolderName)" -type directory -force}
#Moving content to move directory
Move-Item -Path "$($ScriptProperties.FolderDir)\$($ScriptProperties.TempFolderName)\*.*" -Destination "$($ScriptProperties.FolderDir)\$($ScriptProperties.OldFolderName)" -force
#Removing temp directory
Remove-Item "$($ScriptProperties.FolderDir)\$($ScriptProperties.TempFolderName)" -Force
}
write-host "Complete"