{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":32381,"path":"it-service-management/digital-end-user-experience-dex/create-acc-plugin-structure.md","title":"Create an ACC plugin package","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create an ACC plugin package\n\nPackage a PowerShell script, a Ruby script, and an execution allowlist into an Agent Client Collector \\(ACC\\) plugin to run remedial actions on endpoints from the platform.\n\n## Before you begin\n\nRole required: admin\n\n## Procedure\n\n1.  Create a root folder for the ACC plugin in your local computer and name it.\n\n    For example, `acc-dex-custom`.\n\n2.  In the root folder, create two sub-folders named `allowlist` and `bin`.\n\n3.  Create a PowerShell script using PowerShell or command prompt commands to define the remedial action to run on an endpoint device.\n\n    1.  In the `bin` folder, create a `.ps1` file and name it with the `.ps1` extension.\n\n        For example, `CustomScript.ps1`\n\n    2.  Open the `.ps1` file and add the commands.\n\n        For example, the following sample `.ps1` file defines a custom remedial action using commands to stop and start the W32Time process, pause, and restart the Spooler service on a device.\n\n        ```\n        sc.exe stop w32time\n        \n        $process = Get-Process -Name w32time -ErrorAction SilentlyContinue\n        if ($process) {\n            taskkill /f /t /im w32tm.exe\n        }\n        \n        Start-Sleep -Seconds 5\n        \n        sc.exe start w32time\n        Start-Process \"C:\\Windows\\System32\\w32tm.exe\"\n        \n        Start-Sleep -Seconds 5\n        \n        sc.exe stop spooler\n        sc.exe start spooler\n        ```\n\n        **Note:** You can configure the PowerShell script to accept input parameters defined in the ServiceNow instance during execution.\n\n    3.  Save the file.\n\n4.  Create a Ruby script to call the `.ps1` file from the ServiceNow instance.\n\n    1.  In the `bin` folder, create a Ruby file and name it with the `.rb` extension.\n\n    2.  Open the `.rb` file and add your code using plain Ruby or any Ruby framework.\n\n        The Ruby script must include the logic to:\n\n        -   Call the `.ps1` script you created, making sure that you enter the correct file path.\n        -   Validate if the command is successfully executed.\n        -   Create an output JSON that includes the execution status, output, and errors, if any.\n    3.  Execute the command and review the output to confirm if the `.ps1` file is called successfully or if there are any errors.\n\n        For example, the following sample `.rb` file runs a `.ps1` file \\(`CustomScript.ps1`\\) using the acc-f-commons plugin run command, validates if the command runs successfully, and returns the result JSON.\n\n        ```\n        require \"logger\"\n        require_relative \"../../../acc-f-commons/bin/command_runner.rb\"\n        require \"json\"\n        \n        class CustomScript\n          def initialize()\n            @logger = Logger.new(STDOUT)\n            @cmd_runner = CommandRunner.new\n            @logger.level = \"FATAL\"\n          end\n        \n          def execute_custom_script()\n            status = \"failure\"\n            msg = nil\n            data = {}\n        \n            parent_cache_directory = File.expand_path(\"../..\", File.dirname(__FILE__)).gsub(\" \", \"` \")\n            query = \"powershell -ExecutionPolicy Bypass \" + parent_cache_directory + \"/acc-dex-custom/bin/ps/customScript.ps1\"\n        \n            output, error = @cmd_runner.runCmd(query, @logger, \"mode con:cols=32766 lines=1 & chcp 65001 > nul & \", true, false)\n        \n            if !error && !output.empty?\n              status = \"success\"\n              msg = \"Successfully ran script\"\n              data = output\n            else\n              msg = \"Failed - #{error}\"\n            end\n        \n            result = {\n              \"status\" => status,\n              \"type\" => \"device\",\n              \"metric_type\" => \"remedial_action\",\n              \"keys\" => \"custom_script\",\n              \"data\" => data,\n              \"message\" => msg\n            }\n        \n            puts JSON.generate(result)\n          end\n        end\n        \n        custom_script = CustomScript.new\n        custom_script.execute_custom_script()\n        ```\n\n        **Note:**\n\n        If the PowerShell script is configured to accept input parameters from the ServiceNow instance, the Ruby script passes these parameters to the PowerShell script during execution.\n\n5.  Create an allowlist file and specify the Ruby script permitted for execution on endpoint devices.\n\n    1.  In the `allowlist` sub-folder, create an allowlist JSON file.\n\n        For example, `check-allowlist.json`.\n\n    2.  Define any conditions such as arguments to be accepted as part of the `.rb` script, or create a custom logic.\n\n    3.  Save the file.\n\n6.  Generate a `tar.gz` file for your ACC plugin folder using any utility.\n\n    **Note:** The `tar.gz` file name must match the plugin root folder name. For example, `acc-dex-custom.tar.gz`\n\n\n**Parent Topic:**[Creating and executing a PowerShell script-based remedial action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/it-service-management/digital-end-user-experience-dex/remedial-actions-ps.md)\n\n"}}