Results 1 to 6 of 6
  1. #1
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    2,054
    Thanks
    164
    Thanked 194 Times in 187 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
    Now others might well have a slightly more elegant solution to this and I'm happy to receive (polite) suggestions!

    The PS script itself generates a dated logfile name and copies my (changed) files to various other disks and the cloud.
    What do you mean nothing is impossible? I've been doing nothing for years.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,970
    Thanks
    424
    Thanked 1,600 Times in 1,450 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
    How about those eggs!

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    9,012
    Thanks
    64
    Thanked 1,137 Times in 1,058 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

  4. #4
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    9,012
    Thanks
    64
    Thanked 1,137 Times in 1,058 Posts
    Too quick!

    Does "-force" save changes - probably app dependent?

    cheers, Paul

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,970
    Thanks
    424
    Thanked 1,600 Times in 1,450 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
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    2,054
    Thanks
    164
    Thanked 194 Times in 187 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.
    What do you mean nothing is impossible? I've been doing nothing for years.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •