Disclaimer: I have zero understanding of Powershell. Initially I was going to do this in Java, then decided to do a scheduled task instead, (Executing a PoSh script.)

This is what I have:

$ArmA2OA = Get-Process ArmA2OA - ErrorAction SilentlyContinue
$ChkFile =  "C:\Users\Mark27\AppData\Local\ArmA 2 OA\ArmA2OA.rpt"
$FileExists = Test-Path $ChkFile
$currentDate = get-date -uformat "%Y-%m-%d@%H-%M-%S"

       move-item "C:\Users\Mark27\AppData\Local\ArmA 2 OA\ArmA2OA.rpt" ("C:\Users\Mark27\Desktop\A2OA\{0:yyyyMMdd}.rpt" -f (get-date))

What it's supposed to be doing: If the Process A2OA.exe isn't running, check to see if a file ArmA2OA.rpt exists in the directory C:\Users\Mark27\AppData\Local\ArmA 2 OA\. If that is true, then copy and rename the file using current timestamp and send it to C:\Users\Mark27\Desktop\A2OA

If the file doesn't exist, or the process is running, abort.

I've been through a number of questions similar to this, but haven't found my solution. The directory, and file name I'm looking for will always be the same. (This script will be set to execute every 10-15 minutes.)

  • 1
    So what is the error you are getting? – DavidPostill May 22 '17 at 20:18
  • David: It was throwing an error referencing - ErrorAction. Julian provided the answer I was seeking. I had an extra space. Edit: The question was posted as "guest Account". Not entirely sure how to take ownership of the question as the actual account. – Michael Redbourne May 22 '17 at 22:46
  • You need to use the contact us link at the bottom to ask someone from Stack Exchange to merge your accounts.. – Journeyman Geek May 22 '17 at 23:58

You have an extra space in the first command. It should be -ErrorAction, you have - ErrorAction

Also, you don't need any of the else statements.

$currentDate is not needed.

I recommend using PowerShell ISE to help you create these scripts since it lets you step through the script, run partial scripts and is easier to get to help information.


The following script is a bit streamlined. It doesn't explicitly check for the existence of $checkFile but tries Get-Item, if succesfull it is piped to Move-Item.
If uses the ! not operator requiring another pair of parentheses.

$ChkFile =  "C:\Users\Mark27\AppData\Local\ArmA 2 OA\ArmA2OA.rpt"
$Template = "C:\Users\Mark27\Desktop\A2OA\{0:yyyyMMdd}.rpt"

If (!(Get-Process ArmA2OA -ErrorAction SilentlyContinue)){
  Get-Item $chkFile -ErrorAction SilentlyContinue|
    Move-Item -Destination {$Template -f (Get-Date)} -WhatIf

# short version using aliases but equal functionality
# If (!(PS ArmA2OA -EA 0)){GI $chkFile -EA 0|Move -Dest {$Template -f (Get-Date)} -WhatIf}

If the output looks OK remove the -WhatIf

protected by Community Aug 6 '17 at 10:36

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.