Guest User

Untitled

a guest
Oct 18th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class Log {
  2. [string]$path
  3.  
  4. # Constructor
  5. Log ([string] $path) { $this.path = $path }
  6.  
  7. [void] info ([String] $message) {
  8. Write-Host $message
  9. $this.writeFile($message)
  10. }
  11.  
  12. hidden [void] writeFile ([String]$message) {
  13. $message | Add-Content -Path $this.path -EA Stop
  14. }
  15.  
  16. }
  17.  
  18. $block = {
  19. foreach ($y in 1..100) {
  20. ($using:log).info("Logging from RSJob. Test #$y")
  21. }
  22. }
  23.  
  24. Try {
  25. $log = [Log]::New("$PSScriptRoot\test.txt")
  26. foreach($x in 1..100) {
  27. $log.info("Logging from Main function. Test #$x")
  28. }
  29. Start-RSJob -Name "job1" -ScriptBlock $block
  30. While ($true) {
  31. start-sleep 1
  32. }
  33.  
  34. }
  35. Finally {
  36. Get-RSJob -Name "job1" | Remove-RSJob -Force
  37. }
Add Comment
Please, Sign In to add comment