# Custom Script Modules

Source: https://www.jawsdeploy.net/guides/custom-script-modules

Script modules are the function library your inline scripts wish they had.

A script module is a PowerShell module managed by Jaws Deploy that any script step in any project can `Import-Module` and call. It's the right home for helper functions that several scripts share - authentication wrappers, database helpers, notification utilities.

**When the consumer fills out a form**

Templates are actions with UI. Pick from the step picker, fill the inputs, get a step.

**When the consumer writes a script**

Modules are libraries. The consumer is writing their own script and wants to not rewrite a function.

## Inside any script step in any project

The platform handles distribution and version pinning of the module.

```
Import-Module JawsCommon

$token  = Get-AzureToken -Scope $Variables['Azure.Scope']
$conn   = Get-SqlConnection -Variable 'Db.Conn'
$result = Invoke-Migration -Connection $conn -ToVersion $env:ReleaseVersion

Send-SlackNotification -Channel "#deploys" -Message "Deployed v$env:ReleaseVersion to $($Octopus.Environment.Name)"
```

## What belongs in a module

Pure functions used in multiple steps. Logging helpers. Notification senders. Authentication wrappers. Database connection helpers. Things you've written more than once in inline scripts and are tired of re-finding the original.

> **// What does not belong - Anything project-specific.**
> 
> If a function only makes sense inside one project, leave it in the project's inline script. A module shared across projects must be generic enough that someone unfamiliar with the original use case can read it and understand what it does.

