在远程PowerShell上的函数内写入事件日志

时间:2014-08-28 15:15:55

标签: events powershell logging event-log

环境: 服务器:启用了远程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函数,一切正常。但是,如果我输入标准本地用户凭据,则会收到以下错误:日志的注册表项" ToolLog" for source" Schedule"无法打开。

我将函数中的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);

我收到一个错误:异常调用" WriteEntry"用" 3"参数:"无法打开源日志' Schedule'。您可能没有写入权限。"

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

根据我在互联网上找到的所有信息,我已经为我的本地非管理员用户提供了对事件日志的写入权限。通过RegEdit和NTFS实际的事件日志文件。

有什么想法吗?

谢谢, 布赖恩

1 个答案:

答案 0 :(得分:0)

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

相关问题