Is it possible to run a powershell script and tell it to run once a day or hour indefinitely enabling me to not use scheduled task.
It s to copy a file each day. This is my copy script below - its pretty basic as I am beginner.
$source = “\\xxxx\d$\data\home”
$destination1 = “\\xxxx\d$\logs\location1"
$destination2 = “\\xxxx\d$\logs\location2"
$files = Get-ChildItem -Filter *.* -Path $source -Recurse
Foreach($file in $files)
Copy-Item -Path $file.fullname -Destination $destination1 -verbose -PassThru >> c:\scripts\logs\test.log
Copy-Item -Path $file.fullname -Destination $destination2 -verbose -PassThru >> c:\scripts\logs\test.log
you would schedule your powershell script with a scheduled task.
When you schedule the script, make sure you specify "powershell.exe" as application, and submit these as arguments:
-noprofile -executionpolicy bypass -file "c:\pathtoscript.ps1"
Thanks for coming back..
so there is nothing in powershell that I could replace a scheduled task with. Could I not get it to loop every hour\day? or something like this?. Thank you
yes you can:
$hour = 60 * 60
# do something
Start-Sleep -second $hour
} while ($true)
However, for this to work you would first have to launch the script manually, and depending on how robust your solution needs to be, make sure no one closes the powershell session that runs the script.
For your personal use or on your own machine, this may be a doable way.