EventLog和powershell

时间:2015-04-02 14:42:05

标签: windows powershell events logging sysadmin

我创建了一个在创建新帐户时触发的脚本(OnEvent 4720)。我从Event中获取数据并将其作为参数传递给powershell脚本。问题是某些名称有撇号并且不作为参数传递。

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)

然后我拿变量来构建电子邮件的正文。 当它是“John Lee”时一切正常,但是当它是“John O'Connell”时,它就会失败。任何人都知道如何使用撇号传递参数?

由于

0 个答案:

没有答案