PowerShell Write-EventLog CmdLet手动工作,而不是脚本

时间:2015-10-07 16:14:45

标签: powershell event-log cmdlet

我正在编写一个PowerShell脚本来禁用和移动AD中的用户。这部分效果很好。但是我想在事件日志中记录每个事件。当手动输入时,cmdlet Write-EventLog –LogName ManageAD –Source “ManageUsers Script” –EntryType Information –EventID 1 –Message “This is a test message" 可以正常工作。

Write-EventLog –LogName ManageAD –Source “ManageUsers Script” –EntryType Information –EventID 1 –Message “User ” + $SAM + " has been disabled"

Write-EventLog : A positional parameter cannot be found that accepts argument 'Scriptâ??'.
At C:\test\ManageUsers.ps1:12 char:16
+     Write-EventLog <<<<  â?"LogName ManageAD â?"Source â?oManageUsers Scriptâ?? â?"EntryType Information â?"EventID
 â?"Message â?oUser â?? + $SAM + " has been disabled"
    + CategoryInfo          : InvalidArgument: (:) [Write-EventLog], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WriteEventLogCommand

但是,当我将cmdlet添加到脚本时,它会出错。

(B, C)

任何建议都表示赞赏。

0 个答案:

没有答案
相关问题