1

我有 PS 脚本来获取 Regkey 计数到文本文件。我在任务计划程序中使用此脚本&您能否告诉我我们是否可以获取该文件的内容并在任务运行后将其记录到事件查看器中?脚本在下面提到 -

if (!([diagnostics.process]::GetCurrentProcess().Path -match '\\syswow64\\'))
{
$uninstallPath = "\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
$uninstallWow6432Path = "\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
@(
if (Test-Path "HKLM:$uninstallWow6432Path" ) {Get-ChildItem "HKLM:$uninstallWow6432Path"-Recurse | Measure-Object | Out-File "C:\PS Output\Total6432.txt"}
if (Test-Path "HKLM:$uninstallpath" ) {Get-ChildItem "HKLM:$UninstallPath" -Recurse | Measure-Object | Out-File "C:\PS Output\Total32.txt"}
)
}

我尝试了下面提到的以下代码,但在事件查看器中看不到任何内容。你能给我一些指导吗?

if (!([diagnostics.process]::GetCurrentProcess().Path -match '\\syswow64\\'))
{
  $uninstallPath = "\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
  $uninstallWow6432Path = "\Software\Wow6432Node\Microsoft\Windows\CurrentVersion  \Uninstall\"
  @(
  if (Test-Path "HKLM:$uninstallWow6432Path" ) {Get-ChildItem "HKLM:$uninstallWow6432Path"-Recurse | Measure-Object | Out-File "C:\PS Output\Total6432.txt"}
  if (Test-Path "HKLM:$uninstallpath" ) {Get-ChildItem "HKLM:$UninstallPath" -Recurse | Measure-Object | Out-File "C:\PS Output\Total32.txt"}
)

$Content = Get-content -Path 'C:\PS Output\Total6432.txt'
$Content1 = Get-Content -Path 'C:\PS Output\Total32.txt'
{
Write-EventLog -LogName Application -Source $Content AND $Content1 -EventId 3001 -EntryType Information "Count is Registered"
}
}
4

1 回答 1

0

为什么不简单地读取文件的内容并使用类似write-eventlog在脚本末尾写入特定事件日志的命令?你遇到什么问题?

查看http://blogs.msdn.com/b/davethompson/archive/2011/10/25/running-a-scheduled-task-after-another.aspx了解有关运行一项又一项任务的信息,您可以然后创建第二个任务,它只是读取上面的文件并将它们写入事件日志。

如果这不能回答您的问题,那么您到底遇到了什么问题?

于 2012-11-17T20:11:34.973 回答