我正在使用以下行创建一个新的事件日志
new-eventlog -LogName "Visual Studio Builds" -Source "Visual Studio"
Run Code Online (Sandbox Code Playgroud)
我想每次运行它,因为如果我从新计算机运行构建,我仍然希望看到事件日志.
问题是每次在创建日志后运行脚本时,都会抛出错误.
New-EventLog : The "Visual Studio" source is already registered on the "localhost" computer.
At E:\Projects\MyApp\bootstrap.ps1:14 char:13
+ new-eventlog <<<< -LogName "Visual Studio Builds" -Source "Visual Studio"
+ CategoryInfo : InvalidOperation: (:) [New-EventLog], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.NewEventLogCommand
Run Code Online (Sandbox Code Playgroud)
现在我知道我可以"搜索"事件日志
Get-EventLog -list | Where-Object {$_.logdisplayname -eq "Visual Studio Builds"}
Run Code Online (Sandbox Code Playgroud)
但现在我如何确定它是否存在?