I am writing a PowerShell script to disable and move users with in AD. this part works great. However I would like to log each event in the event log. The cmdlet Write-EventLog works fine when typed manually.
Write-EventLog –LogName ManageAD –Source “ManageUsers Script” –EntryType Information –EventID 1 –Message “This is a test message"
However, when I add the cmdlet to the script it errors.
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
Any suggestions are appreciated.
