Otter Documentation

PowerShell & Shell Scripting

  • Last Modified: 2019-07-18

PowerShell is the standard for automating configuration on Windows servers, and Bash/Sh is the standard for automating configuration on Linux servers. Otter was designed to seamlessly integrate with both -- whether that means running your existing scripts across dozens of servers, leveraging scripts built by the community, or a custom combination of both.

While you definitely don't need to be a scripting guru to use Otter, learning how to incorporate scripts into your Otter plans will enable you to automate virtually any aspect of Windows or Linux.

Inline Script Execution

Through PSExec, SHExec and Swim Strings, you can incorporate scripts directly into your Plans.

  • PowerShell
  • Shell
psexec >>
  # delete all but the latest 3 logs in the log directory
     Sort-Object $.CreatedDate -descending |
     Select-Object -skip 3 |
shexec >>
  echo "Hello from $ApplicationName";

Otter will seamlessly replace variables within your powershell script, so in the example above $ApplicationName might be defined as a Configuration Variable.

Calling Scripts

After writing or uploading scripts as an Asset, you can invoke them with PSCall or SHCall as if they were an Operation.

  • PowerShell
  • Shell
pscall CreateUserInDirectory(
  domain: hdars.local,
  user: $UserName

If you use PowerShell's header documentation standards, you'll get descriptions for script arguments when editing in visual mode.

shcall ConfigDirectory(
  arguments: -domain=hdars.local -user=$UserName

Evaluating PowerShell Literals

OtterScript is not a general-purpose programming language, and thus doesn't have built-in support for things like arithmetic. You could, of course, write a custom variable function to support this, but PSEval is much easier:




PowerShell DSC

PowerShell Desired State Configuration (DSC) offers quite a few open-source modules that you can use to configure different features of Windows Servers. With PSDsc, you can invoke DSC Resources in nearly the same manner as a native DSC statement.

PSDsc xWebAppPool (
  Name: AccountsAppPool,
  Ensure: present

These declarative-style statements are essentially Ensure Operations, and thus will collect, report, and remediate drift just like the Built-in Operations.

Ensuring with Scripts

You can also use PowerShell or Shell scripts to gather and ensure a configuration about a server using PSEnsure and SHEnsure.

Built-in Operations vs Scripts

Because a script can do anything, there's an obvious overlap between Otter's built-in operations and a PowerShell CmdLet, or script that you might write.

In general, you should use a built-in Operation when possible. Operations are designed to be massively parallel, cancellation-aware, and highly performant, andvalso provide descriptions when viewed outside of code.

Many scripts, on the other hand, might be written to run interactively (i.e. in a command line), and may prompt for user input if an argument is missing, or does other things not suitable in for non-interactive, scalable environments.

Is this documentation incorrect or incomplete? Help us by contributing!


Generated from commit 7dc9c9e6 on master