2012-11-14 47 views
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" 
} 
} 

回答

0

你爲什麼不只是讀取文件的內容,並在腳本的末尾使用如下命令write-eventlog寫入到一個特定的事件日誌?你遇到什麼問題?

查看http://blogs.msdn.com/b/davethompson/archive/2011/10/25/running-a-scheduled-task-after-another.aspx以獲取關於一個接一個地執行任務的信息,然後可以創建這樣的第二個任務,它只讀取上述文件並將它們寫入事件日誌。

如果這不能回答你的問題,你到底有什麼麻煩?