Maintenance - We're currently working on things and you might experience some issues. Should be wrapped up soon!

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Powershell Startup Scripts (From Group Policy) Running Multiple Times
Post Flair (click to view more posts with a particular flair)
Post Body

Hoping someone has some ideas as to what might cause this...

I have a powershell script that is stored in the policy that on start-up should (as below):

  1. Check if our custom event log has been added to this PC.
  2. Write an event to this log saying that "Robocopy is starting..."
  3. Run robocopy to copy a support folder from a dfs share to the local PC.

$logFileExists = Get-EventLog -list | Where-Object {$_.logdisplayname -eq "YYY-Logs"} 
if (! $logFileExists) {
    New-EventLog -LogName "YYY-Logs" -Source "YYY-Scripts"
}
Write-EventLog -LogName "YYY-Logs" -Source "YYY-Scripts" -EventID 100 -Message "Robocopy Scipt Starting."
robocopy \\YYY.co.uk\Shared\Support$\ C:\Support /MIR

Step 1 seems to be running fine.

Step 2 is definitely running no question but over and over again - in fact it seems to run until a certain time (probably about 5 mins) has elapsed. Cannot really tell though as it is running literally thousands of times before I have logged on and it is hitting the maximum log events on every start-up.

Step 3 is not running.

FYI: If I run the script manually it completes without issue. Have checked the file shares they all have domain computer read access and they have all fully replicated with each other before the script runs.

Have I missed something in the script that says keep restarting the script? Is there a setting in group policy I have overlooked? Is it a symptom of something else or another problem entirely?

Any suggestions are welcome but I'm currently thinking about what hammer would do the most damage to the server. Thanks!

EDIT: Solved

Turns out that having dollar signs and the name of the script were causing the script to call itself recursively, renamed and escaped the $ and it worked fine.

Thanks to all those that provided debugging steps etc.

Author
Account Strength
100%
Account Age
10 years
Verified Email
Yes
Verified Flair
No
Total Karma
10,696
Link Karma
1,084
Comment Karma
9,368
Profile updated: 1 day ago
Posts updated: 10 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago