Rick0

LOG_EXTRACT

Apr 3rd, 2020
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Host.UI.RawUI.WindowTitle = "LOGS VPN EM TEMPO REAL"
  2. $dateStr = Get-Date -Format "yyyy-MM-dd"
  3. $flog = Get-Date -Format "yyyy/MM/dd"
  4. $dir = $flog.replace('/','\')
  5. #LOG VPN
  6. $logFile = '\\servidor\log\-'+$dateStr+'.txt'
  7. if (!(test-path -path $dir)) {new-item -path $dir -itemtype directory}
  8. #LOG SENHA INCORRETA
  9. $logpw = '.\'+$dir+'\SENHA-INCORRETA.txt'
  10. #LOG CONTA BLOQUEADA
  11. $loglocked = '.\'+$dir+'\CONTA-BLOQUEADA.txt'
  12. #LOG USUARIO NAO ENCONTRADO
  13. $svpn = '.\'+$dir+'\SEMVPN-CADASTRADA.txt'
  14. #LOG USUARIO AGUARDANDO TOKEN
  15. $utoken = '.\'+$dir+'\AGUARDANDO-TOKEN.txt'
  16. #LOG USUARIO TOKEN INCORRETO
  17. $utokenerr = '.\'+$dir+'\TOKEN-INVALIDO.txt'
  18. Clear-Host
  19. GC -Wait $logFile  |
  20.  % {
  21.         $Status = $_
  22.         if ($Status.Contains('status="Success"')) {Write-Host $Status -Foreground Green}#OK
  23.         elseif ($Status.Contains('expecting email token')) {Write-Host $Status -Foreground Yellow
  24.         $Status -replace '\s\-Foreground Yellow', '' -match 'user="(.*?)"'
  25.         $matches[1] | Out-File -FilePath $utoken -Append -Encoding UTF8} #AGUARDANDO TOKEN
  26.         elseif ($Status.Contains('invalid password')) {Write-Host $Status -Foreground Red
  27.         $Status -replace '\s\-Foreground Red', ''  -match 'user="(.*?)"'
  28.         $matches[1] | Out-File -FilePath $logpw -Append -Encoding UTF8} #SENHA INCORRETA
  29.         elseif ($Status.Contains('user locked')) {Write-Host $Status -Foreground Magenta
  30.         $Status -replace '\s\-Foreground Magenta', '' -match 'user="(.*?)"'
  31.         $matches[1] |  Out-File -FilePath $loglocked -Append -Encoding UTF8} #CONTA BLOQUEADA
  32.         elseif ($Status.Contains('user not found')) {Write-Host $Status -Foreground Cyan
  33.         $Status -replace '\s\-Foreground Cyan', '' -match 'user="(.*?)"'
  34.         $matches[1] | Out-File -FilePath $svpn -Append -Encoding UTF8} #SEM VPN
  35.         elseif ($Status.Contains('invalid token')) {Write-Host $Status -Foreground DarkCyan
  36.         $Status -replace '\s\-Foreground DarkCyan', '' -match 'user="(.*?)"'
  37.         $matches[1] | Out-File -FilePath $utokenerr -Append -Encoding UTF8} #TOKEN INVALIDO
  38.         else {Write-Host $Status} #SAIDA COMUM
  39.  }
Add Comment
Please, Sign In to add comment