I`ve a script that triggers when new account is created (OnEvent 4720). I takes the data from the Event and pass it as a parameter to a powershell script. The problem is some names have a apostrophe and are not passed as a parameter.
TaskConfig:
...
<Value name="DisplayName">Event/EventData/Data[@Name='DisplayName']</Value>
...
TaskAction:
<Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
<Arguments>-Command c:\script\SendEmailNA.ps1 -SubjectUserSid '$(SubjectUserSid)' -SubjectUserName '$(SubjectUserName)' -SubjectDomainName '$(SubjectDomainName)' -SubjectLogonId '$(SubjectLogonId)' -TargetSid '$(TargetSid)' -TargetUserName '$(TargetUserName)' -TargetDomainName '$(TargetDomainName)' -SamAccountName '$(SamAccountName)' -DisplayName '$(DisplayName)' -UserPrincipalName '$(UserPrincipalName)' -HomeDirectory '$(HomeDirectory)' -HomePath '$(HomePath)' -ScriptPath '$(ScriptPath)' -ProfilePath '$(ProfilePath)' -UserWorkstations '$(UserWorkstations)' -PasswordLastSet '$(PasswordLastSet)' -AccountExpires '$(AccountExpires)' -PrimaryGroupId '$(PrimaryGroupId)' -AllowedToDelegateTo '$(AllowedToDelegateTo)' -OldUacValue '$(OldUacValue)' -NewUacValue '$(NewUacValue)' -UserAccountControl '$(UserAccountControl)' -UserParameters '$(UserParameters)' -SidHistory '$(SidHistory)' -LogonHours '$(LogonHours)' -PrivilegeList '$(PrivilegeList)'</Arguments>
SendEmailNA.ps1:
param($SubjectUserSid, $SubjectUserName, $SubjectDomainName, $SubjectLogonId, $TargetSid, $TargetUserName, $TargetDomainName, `
$SamAccountName, $DisplayName, $UserPrincipalName, $HomeDirectory, $HomePath, $ScriptPath, $ProfilePath, $UserWorkstations, `
$PasswordLastSet, $AccountExpires, $PrimaryGroupId, $AllowedToDelegateTo, $OldUacValue, $NewUacValue, $UserAccountControl, `
$UserParameters, $SidHistory, $LogonHours, $PrivilegeList)
And then i take the variable to construct the body of a email. Everything works fine when it's "John Lee" but when it's "John O'Connell" it fails. Anybody have an idea how to pass an parameter with a apostrophe?
Thanks