Results 1 to 6 of 6
Thread: Robocopy and Powershell
-
2018-06-15, 08:56 #1
- Join Date
- Dec 2009
- Location
- Oxfordshire, UK
- Posts
- 2,175
- Thanks
- 177
- Thanked 218 Times in 205 Posts
Robocopy and Powershell
I was looking at this thread, looking for a parameter I wanted to change when I noticed that RG hadn't closed Outlook and this caused a problem. Now I might be teaching granddad to suck eggs, but I run my Robocopy in Powershell and run this via a batch file. And I have a little reminder to close Outlook (and Thunderbird) before continuing, having got fed up with waiting for the scripts to finish. All it is is as follows:
Code:echo "Shut down Outlook and Thunderbird" Pause @ECHO OFF PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}" PAUSE
The PS script itself generates a dated logfile name and copies my (changed) files to various other disks and the cloud.Cartophilia rocks
-
2018-06-15, 09:11 #2
- Join Date
- Mar 2004
- Location
- Manning, South Carolina
- Posts
- 10,161
- Thanks
- 450
- Thanked 1,655 Times in 1,488 Posts
Access,
Why use a .bat at all do it all in PowerShell.
Code:Get-Process "Outlook" | Foreach-Object { $_.CloseMainWindow() | Out-Null } | stop-process –force
HTHMay the Forces of good computing be with you!
RG (still RetiredGeek on AskWoody.com)
PowerShell & VBA Rule!
My Systems: Desktop Specs
Laptop Specs
-
2018-06-15, 09:25 #3
- Join Date
- Dec 2009
- Location
- Earth
- Posts
- 9,179
- Thanks
- 69
- Thanked 1,165 Times in 1,083 Posts
A neater solution would be to look for the Outlook and TB executables (tasklist /FI "imagename eq thunderbird.exe") and prompt the user if they are running.
Even better to do it in PowerShell (Get-Process thunderbird).
cheers, Paul
-
2018-06-15, 09:27 #4
- Join Date
- Dec 2009
- Location
- Earth
- Posts
- 9,179
- Thanks
- 69
- Thanked 1,165 Times in 1,083 Posts
Too quick!
Does "-force" save changes - probably app dependent?
cheers, Paul
-
2018-06-15, 09:33 #5
- Join Date
- Mar 2004
- Location
- Manning, South Carolina
- Posts
- 10,161
- Thanks
- 450
- Thanked 1,655 Times in 1,488 Posts
Access,
Here's the entire thing in a tested PS Script:
Code:Get-Process "Outlook" | Foreach-Object { $_.CloseMainWindow() | Out-Null } | stop-process -force -ErrorAction "SilentlyContinue" RoboCopy.exe "G:\BEKDocs" "\\MYBOOKLIVE\CMShared\%COMPUTERNAME%\BEKDocs" /MIR /XJD /R:5 /W:15 /MT:32 /V /NP /XD "G:\BEKDocs\OneDrive" "G:\BEKDocs\diagnostics" "G:\BEKDocs\Images to Post" "G:\BEKDocs\Samsung" /IT /LOG+:G:\BEKDocs\Batch\BackupTasks\RoboCopyNAS.log
May the Forces of good computing be with you!
RG (still RetiredGeek on AskWoody.com)
PowerShell & VBA Rule!
My Systems: Desktop Specs
Laptop Specs
-
2018-06-15, 10:29 #6
- Join Date
- Dec 2009
- Location
- Oxfordshire, UK
- Posts
- 2,175
- Thanks
- 177
- Thanked 218 Times in 205 Posts
Well here's food for thought from you guys (as I expected!) The only reason I use a batch file is that I can just double click it in File Explorer and away it goes. When I try that with PS it doesn't - I'm probably missing something there. I'll try your PS script (with suitable changes of course!) when I next run the backup.
Cartophilia rocks