【问题标题】:Write-EventLog within Function over Remote PowerShell通过远程 PowerShell 在函数中写入事件日志
【发布时间】:2014-10-22 12:38:45
【问题描述】:

环境: 服务器:启用远程 PowerShell 的 Windows Server 2012 R2。 工作站:Windows 8.1

所以我创建了一个名为 MyModule.psm1 的 PowerShell 模块,具有以下功能:

Function CreateEvent() {

Write-EventLog –LogName ToolLog –Source “Schedule” –EntryType Information –EventID 13 –Message “There were users written to the database.”

}

我创建了一个 PSSessionConfigurationFile ,然后用 EventLogging 的配置名称注册了它,这样我就可以通过以下方式远程 powershell:

$Creds = Get-Credential
$SessionOpts = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
$Session = New-PSSession -ComputerName Server.Domain.Com -ConfigurationName EventLogging -Credential $Creds -UseSSL -SessionOption $SessionOpts
Import-PSSession $Session

现在,当我在 Get-Credential 中输入本地管理员凭据时,我可以运行函数 CreateEvent 并且一切正常。但是,如果我输入标准本地用户凭据,则会收到以下错误:无法打开源“Schedule”的日志“ToolLog”的注册表项。

我将函数中的 Write-EventLog 替换为:

$EventLog = new-object System.Diagnostics.EventLog("ToolLog");
$EventLog.MachineName = ".";
$EventLog.Source = "Schedule";
$EventLog.WriteEntry("There were users written to the database.", "Information", 15);

我收到以下错误:使用“3”参数调用“WriteEntry”的异常:“无法打开源'Schedule'的日志。您可能没有写入权限。”

如果我在本地登录服务器并导入模块并尝试运行该功能,我会得到完全相同的错误。我自己也无法运行 Write-EventLog 的 cmdlet。

根据我在 Internet 上找到的所有信息,我已授予本地非管理员用户对事件日志的写入权限。通过 RegEdit 和实际事件日志文件上的 NTFS。

有什么想法吗?

谢谢, 布赖恩

【问题讨论】:

  • 嗨,布赖恩,你有什么发现吗?

标签: events powershell logging event-log


【解决方案1】:

据我了解,只有管理员才能创建新的事件日志。我不确定是否有办法解决这个问题。我建议提前以管理员身份在您的服务器上添加新的事件日志,以便在非管理员尝试写入之前,事件日志就在那里。

【讨论】:

  • 嗨 Aaron,我已经从管理员帐户创建了事件日志。当我尝试将事件写入该事件日志时,我收到了错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-29
  • 2014-02-06
  • 2013-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多