Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <#
  2. This is a simple autoremediation that just prints a hello world message.
  3.  
  4. You need to import and extend the BaseAR class so that you get hooks such as $this.writeOutput
  5. so that you can log the message
  6.  
  7. Also notice how we have @requiredArgs instance variable. This is where you declare the mandatory arguments
  8. for your auto remediation. If the required arguments aren't passed, then the AR would fail even before calling the execute method
  9.  
  10. The needsExecution method is method that mandatory method that you must implement. This is the place where you check if running the AR is required.
  11. This helps us to execute the AR, only if it is required. You have to return a $true or $false from this.
  12.  
  13. If the needsExecution method returns $true, then the execute method is called. This is where you actually write code for the autoremediation.
  14.  
  15. You can test this locally by running
  16. pwsh run.ps1 -arclass HelloWorldAR -message "Human"
  17. #>
  18.  
  19. # Import BaseAR. Make sure that you have got the path correct
  20. using module ..\..\Lib\Classes\BaseAR.psm1
  21.  
  22.  
  23. class HelloWorldAR: BaseAR {
  24. # Declare mandatory arguments needed for the AR to run correctly
  25. [array]$requiredArgs = @("message")
  26.  
  27. # Decide, if the AR needs to run
  28. [bool] needsExecution($kwargs) {
  29. return $true
  30. }
  31.  
  32. # Decide, if the AR needs to run
  33. [bool] verifySuccess($kwargs) {
  34. return $true
  35. }
  36.  
  37. # Run the auto remediation
  38. [bool] execute($kwargs) {
  39. $message = $kwargs["message"]
  40.  
  41. # $this.writeOutput and $this.writeError let you write to stdout and stderr
  42. $this.writeOutput("Hello World $message")
  43.  
  44. return $true
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement