Set-EventSource.ps1

function Set-EventSource
{
  <#
      .SYNOPSIS
      Set the eventSource of the message to be recorded in the eventlog "RMMScript"
      Default is "undefined"
      Typically, eventSource should be one of the following:
          SystemServer
          SystemWorkstation
          HardwareServer
          HardwareWorkstation
          Security
          Backup
          Software
          Internet
          Printer
          NAS
          Network
          Telecom
          Mobility
      .EXAMPLE
      Set-EventSource "Backup"
  #>

  [CmdletBinding()]
  param
  (
    [Parameter(Mandatory=$false, Position=0)]
    [System.Object]
    $EventSource
  )
  $global:EventSource ="RMM"+$EventSource 
  
  $global:EventOK = $global:EventSource + "OK"
  $global:EventERROR = $global:EventSource + "ERROR" 

  $global:Output = ""
  $Global:ErrorCount = 0
  
  $templog = $(try { Get-EventLog -LogName $global:EventLog -Newest 1 -Source $global:EventSource -ErrorAction Ignore } catch{}) -ne $null
    if (!$templog) 
    { 
    New-EventLog -LogName $global:EventLog -Source $global:EventSource | out-null 
    }

$evtinfo = "Start " + $MyInvocation.ScriptName
Write-EventLog -LogName $global:EventLog -Source $global:EventSource -EntryType Information -EventID 999 -Message $evtinfo

$Global:StartTime = get-date
}