My main PowerShell code runs a function that logs to the Windows eventlog. If the level is error it uses a separate event ID which then our monitoring will pick up that exact ID and run an action. However, if I want to specify in the parameter of the main script (not the function) that this time running it use a different Event ID so it will NOT action monitoring, I don't know where to even start on that.

Is there a way to provide a switch parameter in the main script like `$NoAlert` which then changes the Event ID in the function?

The function of logging lives in a PowerShell module I created. I am importing the module at the beginning of the script and then calling the function during the main script body.

Here is the function:

```
function WriteLog-SRTProd {
    Param(
        [string]$logT,
        [Parameter(Mandatory=$true)][string]$level,
        [String]$LogFileDirT = "\\ServerA\Logs"
    )

    $RSLogfileT = (Get-ChildItem -Path $LogFileDirT |
                  sort LastWriteTime |
                  select -Last 1).Name

    ## make sure a level is correctly selected (mandatory)
    if ("Error","Info","Warn" -NotContains $Level) {
        throw "$($Environment) is not a valid name! Please use 'Error', 'Warn', or 'Info'"
    }
    if ($Level -eq "Info") {
        Add-Content -Path "$LogFileDirT\$RSLogFileT" -Value "$(Get-Date -format MM-dd-yyyy::HH:mm:ss)  INFO   $logT"
        Write-EventLog -LogName Application -Source TEST_MAINT -EntryType Information -EventId 100 -Message $logT -Category 0
    }
    if ($Level -eq "Warn") {
        Add-Content -Path "$LogFileDirT\$RSLogFileT" -Value "$(Get-Date -format MM-dd-yyyy::HH:mm:ss)  WARN   $logT"
        Write-EventLog -LogName Application -Source TEST_MAINT -EntryType Warning -EventId 200 -Message $logT -Category 0
    }
    if ($Level -eq "Error") {
        Add-Content -Path "$LogFileDirT\$RSLogFileT" -Value "$(Get-Date -format MM-dd-yyyy::HH:mm:ss)  ERROR  $logT"
        Write-EventLog -LogName Application -Source TEST_MAINT -EntryType Error -EventId 300 -Message $logT -Category 0
    }
}

```

I'd like to run my script like this. When the `$NoAlert` is passed, it will send that switch to the function. Is this possible? Can I just add the switch in both places and use an `if` statement in the function for when the NoAlert switch is used?

```

PS C:\> .\Maintenance.ps1 -NoAlert

```

```
Param(
    [switch]$NoAlert
)

WriteLog-SRTProd -level Error -logT "Custom Error Message"

```