Advertisement
opexxx

eventlogbackup.ps1

Mar 8th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #requires -version 3.0
  2.  
  3. #remote computers must be running PowerShell 3.0
  4.  
  5. $computers = "chi-dc01","chi-fp01","chi-dc04","chi-fp02"
  6. $cred = Get-Credential globomantics\administrator
  7. $eventlog = "Application"
  8.  
  9. invoke-command -ScriptBlock {
  10.   $log = get-wmiobject win32_nteventlogfile -filter "logfilename = '$using:eventlog'"
  11.   $file = "{0}_{1}_{2}.evtx" -f (get-date -f "yyyyMMdd"),$log.CSName,$log.FileName.Replace(" ","")
  12.  
  13.   #map a PSDrive with credentials
  14.   New-PSDrive -name B -PSProvider Filesystem -Root \\chi-fp01\it -Credential $using:cred | Out-Null
  15.  
  16.   #backup path must be something Windows can see like a UNC
  17.   $backup = join-path (get-psdrive B).root $file
  18.   write-host "Backing up to $backup" -ForegroundColor cyan
  19.   $r = $log | Invoke-WmiMethod -Name BackupEventlog -ArgumentList $backup
  20.   if ($r.returnValue -eq 0) {
  21.     Get-Item $backup
  22.   }
  23.   else {
  24.    Throw "Backup failed with returnvalue $($r.returnvalue)"
  25.   }
  26.  
  27.  } -ComputerName $computers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement