README! How to use scripts

These guidelines are here to help you get started with running API scripts for Hudu in PowerShell. If you're new to API scripting, you can read more about PowerShell and APIs here.

Important Notes

  • Prior to using API scripts, ensure you fully understand what each script accomplishes.

  • The scripts shared here are created by the community and may not have been verified by the Hudu team. Use these scripts at your own risk.


Prerequisites

  • Access to your Hudu instance (trial or paid version).

  • PowerShell installed on your system.

  • A text editor, such as:

    • Visual Studio Code

    • PowerShell ISE

    • Notepad++

    • Cursor


Using Powershell Scripts

Set Up Your Environment

  1. Prepare a folder:

    • Create a folder on your computer to store your scripts (e.g., PowerShell).

  2. Create a new script file:

    • In your text editor, create a new file and save it with a .ps1 extension (e.g., ScriptName.ps1).

Add the Script Code

  1. Locate the script you want to use in the community library.

  2. Copy the code and paste it into the .ps1 file you created.

  3. Save the file.

Install the HuduAPI Module (this may be included in script itself)

  1. Check if the HuduAPI module is already installed:

    Get-Module -ListAvailable -Name HuduAPI
  2. If not installed, download it from the HuduAPI GitHub repository and add it to your PowerShell modules directory, or follow the installation instructions provided on GitHub.


Configuring the Script

Set up your API key

  1. Generate a new API key:

    • All scripts require a Hudu API key and your Hudu URL. There are several ways to do this. The method we are explaining is one of the options generally considered more secure.

      • In Hudu, navigate to Admin > API Keys > + New API Key.

      • Configure the key based on the script's requirements.

  2. Store the API key securely:

    • Rather than hardcoding API keys into the script, use a secure method like:

Configure Variables

  1. Replace placeholders (e.g., Hudu URL and API key) in the script with your actual values.

    • Please note: Since the Script Library is community-driven, scripts may not all follow the same practices for key storage. Code for using Azure Key Vault can be found at the bottom of this article.

  2. If using Azure Key Vault, ensure the script includes appropriate commands to fetch the API key securely.

Save the Script


Running the Script

  1. Open PowerShell:

    • Open the PowerShell terminal.

    • If using PowerShell Core, type pwsh to access PowerShell commands.

  2. Navigate to the Script Directory:

    • Use the cd command to move to the folder where your script is saved:

      cd Path\To\Your\Scripts

  3. Run the Script:

    • Execute the script by typing:

      ./ScriptName.ps1

      • Replace this with the actual file name.

  4. Authenticate (if required):

    • If using Azure Key Vault, log in to Azure when prompted.

  5. Verify Results:

    • Check your Hudu environment to ensure the script executed correctly.


Additional Tips

  • Always test scripts in a non-production environment first.

  • Regularly review and update scripts to align with Hudu and API changes.

4