Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- This is a simple autoremediation that just prints a hello world message.
- You need to import and extend the BaseAR class so that you get hooks such as $this.writeOutput
- so that you can log the message
- Also notice how we have @requiredArgs instance variable. This is where you declare the mandatory arguments
- for your auto remediation. If the required arguments aren't passed, then the AR would fail even before calling the execute method
- 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.
- This helps us to execute the AR, only if it is required. You have to return a $true or $false from this.
- If the needsExecution method returns $true, then the execute method is called. This is where you actually write code for the autoremediation.
- You can test this locally by running
- pwsh run.ps1 -arclass HelloWorldAR -message "Human"
- #>
- # Import BaseAR. Make sure that you have got the path correct
- using module ..\..\Lib\Classes\BaseAR.psm1
- class HelloWorldAR: BaseAR {
- # Declare mandatory arguments needed for the AR to run correctly
- [array]$requiredArgs = @("message")
- # Decide, if the AR needs to run
- [bool] needsExecution($kwargs) {
- return $true
- }
- # Decide, if the AR needs to run
- [bool] verifySuccess($kwargs) {
- return $true
- }
- # Run the auto remediation
- [bool] execute($kwargs) {
- $message = $kwargs["message"]
- # $this.writeOutput and $this.writeError let you write to stdout and stderr
- $this.writeOutput("Hello World $message")
- return $true
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement