skip to Main Content

In my DOCKERFILE I’m running some PowerShell script which creates a custom event log (on Windows Server), then writes an entry. [I should add that I’m currently doing this only for debug purposes.]

The script/command which creates the event log appear to execute without any problems, but an exception is thrown when writing to the log using…

RUN powershell.exe -command Write-EventLog -LogName "my_log_name" -Source "my_source" -Message "EventLog created by DOCKERFILE." -Category 0 -EventID 0 -EntryType Information

The following exception is thrown…

Write-EventLog : A positional parameter cannot be found that accepts argument 
'created'.
At line:1 char:1
+ Write-EventLog -LogName my_log_name -Source my_source -EntryType Messag ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Write-EventLog], Parameter 
   BindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell 
   .Commands.WriteEventLogCommand

I also tried wrapping "EventLog created by DOCKERFILE." in parentheses but then it complained about the word by.

Why does it seem unable to parse "EventLog created by DOCKERFILE." as a string argument, but is instead parsing the words within the string?


UPDATE
Even if I wrap the command in double-quotes and the individual strings in single quotes, I get the same error.

enter image description here


UPDATE 2
Removing the quotes and escaping the spaces doesn’t work either.

enter image description here

2

Answers


  1. You need to use ` to escape the spaces:

    RUN powershell.exe -command Write-EventLog -LogName my_log_name -Source my_source -Message EventLog` created` by` DOCKERFILE. -Category 0 -EventID 0 -EntryType Information
    

    See: https://docs.docker.com/engine/reference/builder/#escape

    Login or Signup to reply.
  2. This works for me from cmd (except for the unknown source). I’m not sure if docker has issues with single quotes. Double quotes are special in cmd. Note that new-winevent has replaced write-eventlog.

    powershell write-eventLog my_log_name my_source 0 information 'EventLog created by DOCKERFILE.' -category 0
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search