【发布时间】: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