Windows - Create Event Source

Octopus.Script exported 2015-06-20 by HumanPrinter belongs to ‘Windows’ category.

Establishes the specified source name as a valid event source for writing entries to a log on the local computer.

This method can also create a new custom log on the local computer.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Source name

EventSourceName

The source name by which the application is registered on the local computer.

Log name

EventLogName = Application

The name of the log the source’s entries are written to. Possible values include Application, System, or a custom event log.

Script body

Steps based on this template will execute the following PowerShell script.

$sourceName = $OctopusParameters["EventSourceName"]
$logName = $OctopusParameters["EventLogName"]

$sourceExists = [System.Diagnostics.EventLog]::SourceExists($sourceName)
if($sourceExists) {
	Write-Output "Event source $sourceName already exist."
	return
}

[System.Diagnostics.EventLog]::CreateEventSource($sourceName, $logName)

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "6047c2b5-95f7-46db-85b4-d970c1586f94",
  "Name": "Windows - Create Event Source",
  "Description": "Establishes the specified source name as a valid event source for writing entries to a log on the local computer. \n\nThis method can also create a new custom log on the local computer.",
  "Version": 5,
  "ExportedAt": "2015-06-20T10:04:09.578+00:00",
  "ActionType": "Octopus.Script",
  "Author": "HumanPrinter",
  "Parameters": [
    {
      "Name": "EventSourceName",
      "Label": "Source name",
      "HelpText": "The source name by which the application is registered on the local computer.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "EventLogName",
      "Label": "Log name",
      "HelpText": "The name of the log the source's entries are written to. Possible values include Application, System, or a custom event log.",
      "DefaultValue": "Application",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "$sourceName = $OctopusParameters[\"EventSourceName\"]\n$logName = $OctopusParameters[\"EventLogName\"]\n\n$sourceExists = [System.Diagnostics.EventLog]::SourceExists($sourceName)\nif($sourceExists) {\n\tWrite-Output \"Event source $sourceName already exist.\"\n\treturn\n}\n\n[System.Diagnostics.EventLog]::CreateEventSource($sourceName, $logName)",
    "Octopus.Action.Script.Syntax": "PowerShell"
  },
  "Category": "Windows",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/windows-create-eventsource.json",
  "Website": "/step-templates/6047c2b5-95f7-46db-85b4-d970c1586f94",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////Da3qSsLvhtb0wur6O7zuWcfxldv2aMzyK7ftpOD3s+X48Pr+0fD7d9HzHLLr4fX8xD/OcwAAAaNJREFUeNrs3cFygjAUQFECWott1f//2sJoW6kIKEzNs+euXOmcmSSGDa8oJEmSJEmSJGmsj1W1K9cpsGD1Vr2WdToVEPC+2lYvZfpVrEW0qZpF1F+MRdRugzoNlvkiarfBPk0pT8GhWUSX2yASpDlLr2+DEJBmEY1ug6whx7N0n2b30G1QlmmxHsRYp6X76yvF9vg5RYQczq8UVURI35UiFmTgShED0p6lI1eKzCHTrxS5Qk6PZ9PLDtJ9PIsJmXWlyAky6/dAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQMJCyjltF/iO3gpJUpD8s4OAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgID8T8itwwKyhbTdMr4ha8hXUwZqhICcOgyNOIkE+V5wo4MSgr1u/fp7poO+AL8K/gL8yw0UeyRB34m9iQ/pVD8L5JYTO3NI58R+AsiEEzsW5OfE3sUe/zRwYkeGnG2g2CPS7rhjF4GKP0ZwyoldxK37kFqEL/7wU0mSJEmSJOmJ+xRgAHxZTCXGdZkfAAAAAElFTkSuQmCC",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Saturday, June 20, 2015