1

Regkey カウントをテキスト ファイルに取得する PS スクリプトがあります。タスク スケジューラでこのスクリプトを使用しています。そのファイルの内容を取得して、タスクの実行後にイベント ビューアに記録できるかどうか教えてください。スクリプトは以下に記載されています-

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 を参照してください次に、上記のファイルを単純に読み取り、イベント ログに書き込む 2 番目のタスクを作成します。

これで質問の答えが得られない場合、具体的にどのような問題が発生していますか?

于 2012-11-17T20:11:34.973 に答える