PuppetBolt.psm1

function Invoke-BoltCommandline {
  [CmdletBinding()]
  param($params)

  Write-Verbose "Executing bolt $($params -join ' ')"

  bolt $params
}

function Get-BoltCommandline {
  param($parameterHash, $mapping)

  $common = @(
    'ErrorAction', 'ErrorVariable', 'InformationAction',
    'InformationVariable', 'OutBuffer', 'OutVariable', 'PipelineVariable',
    'WarningAction', 'WarningVariable', 'Confirm', 'Whatif'
  )

  $params = @()
  foreach ($kvp in $parameterHash.GetEnumerator()) {
    if ($kvp.Key -in $common) {
      Write-Verbose "Skipping common parameter: $($kvp.Key)"
      continue
    }
    else {
      Write-Verbose "Examining $($kvp.Key)"
    }
    $pwshParameter = $kvp.Key
    $pwshValue = $kvp.Value
    $rubyParameter = $mapping[$pwshParameter]

    if ($pwshValue -is [System.Management.Automation.SwitchParameter]) {
      Write-Verbose "Parsing $($kvp.key) as switch parameter"
      if ($pwshValue -eq $true) {
        $params += "--$($rubyParameter)"
      }
      else {
        $params += "--no-$($rubyParameter)"
      }
    }
    elseif ($pwshValue -is [System.Collections.Hashtable]) {
      Write-Verbose "Parsing $($kvp.key) as hashtable parameter"
      $v = ConvertTo-Json -InputObject $pwshValue -Compress
      $params += "--$($rubyParameter)"
      # $IsLinux/IsMacOS are an automatic variables from powershellcore:
      # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.1#islinux
      $IsLinuxEnv = (Get-Variable -Name "IsLinux" -ErrorAction Ignore) -and $IsLinux
      $IsMacOSEnv = (Get-Variable -Name "IsMacOS" -ErrorAction Ignore) -and $IsMacOS
      $IsWinEnv = !$IsLinuxEnv -and !$IsMacOSEnv
      if($IsWinEnv){
        $params += "'$($v)'"
      } else {
        # Commands run on Linux/Mac platforms will fail because the
        # the interpolation of the command from powershell -> .NET -> Ruby
        # will end up stripping out quotes that aren't baskslash-escaped.
        #
        # See https://github.com/MicrosoftDocs/PowerShell-Docs/issues/2361
        $params += $v -replace '"', '\"'
      }
    }
    elseif ($pwshValue.GetType().Name -eq 'List`1') {
      Write-Verbose "Parsing $($kvp.key) as array parameter"
      $pwshValue | Foreach-Object {
        $params += "$($_)"
      }
    }
    else {
      Write-Verbose "Parsing $($kvp.key) as default"
      if ($rubyParameter) {
        $params += "--$($rubyParameter)"
      }

      $parsedValue = switch ($pwshParameter) {
        'params' { "'$($pwshValue)'" }
        'execute' { "'$($pwshValue)'" }
        Default { $pwshValue }
      }

      $params += $parsedValue
    }
  }

  Write-Output $params
}

function Get-BoltVersion{
  [CmdletBinding()]
  param()

  $module = Get-Module -Name PuppetBolt
  Write-Output [string]($module.Version)
}

# AUTOGENERATED BY BOLT
# DO NOT MODIFY
$script:mapping = @{
"Verbose" = "verbose"
"Manifest" = ""
"Targets" = "targets"
"Query" = "query"
"Rerun" = "rerun"
"User" = "user"
"Password" = "password"
"PasswordPrompt" = "password-prompt"
"PrivateKey" = "private-key"
"HostKeyCheck" = "host-key-check"
"Ssl" = "ssl"
"SslVerify" = "ssl-verify"
"RunAs" = "run-as"
"SudoPassword" = "sudo-password"
"SudoPasswordPrompt" = "sudo-password-prompt"
"SudoExecutable" = "sudo-executable"
"Concurrency" = "concurrency"
"Inventoryfile" = "inventoryfile"
"SaveRerun" = "save-rerun"
"Cleanup" = "cleanup"
"Project" = "project"
"Modulepath" = "modulepath"
"Transport" = "transport"
"ConnectTimeout" = "connect-timeout"
"TTY" = "tty"
"NativeSsh" = "native-ssh"
"SshCommand" = "ssh-command"
"CopyCommand" = "copy-command"
"Format" = "format"
"Color" = "color"
"Trace" = "trace"
"Stream" = "stream"
"LogLevel" = "log-level"
"ClearCache" = "clear-cache"
"Noop" = "noop"
"Execute" = "execute"
"CompileConcurrency" = "compile-concurrency"
"HieraConfig" = "hiera-config"
"Command" = ""
"EnvVar" = "env-var"
"Source" = ""
"Destination" = ""
"Tmpdir" = "tmpdir"
"Detail" = "detail"
"Key" = ""
"Module" = ""
"Force" = "force"
"Resolve" = "resolve"
"Name" = ""
"Filter" = "filter"
"Params" = "params"
"Pp" = "pp"
"Modules" = "modules"
"Script" = ""
"Arguments" = ""
"Text" = ""
"Plugin" = "plugin"
}


<#
.SYNOPSIS
  bolt apply [manifest] {--targets TARGETS | --query QUERY | --rerun FILTER}
      [options]
.DESCRIPTION
  Apply Puppet manifest code on the specified targets.
.PARAMETER Manifest
  The manifest to apply
.PARAMETER Targets
  Identifies the targets of the command.
  For more information, see 'bolt guide targets'.
.PARAMETER Query
  Query PuppetDB to determine the targets.
.PARAMETER Rerun
  Retry on targets from the last run.
  Available filters are 'all', 'failure', and 'success'.
.PARAMETER User
  User to authenticate as.
.PARAMETER Password
  Password to authenticate with.
.PARAMETER PasswordPrompt
  Prompt for user to input password.
.PARAMETER PrivateKey
  Path to private ssh key to authenticate with.
.PARAMETER HostKeyCheck
  Check host keys with SSH.
.PARAMETER Ssl
  Use SSL with WinRM.
.PARAMETER SslVerify
  Verify remote host SSL certificate with WinRM.
.PARAMETER RunAs
  User to run as using privilege escalation.
.PARAMETER SudoPassword
  Password for privilege escalation.
.PARAMETER SudoPasswordPrompt
  Prompt for user to input escalation password.
.PARAMETER SudoExecutable
  Experimental. Specify an executable for running as another user.
.PARAMETER Concurrency
  Maximum number of simultaneous connections.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER SaveRerun
  Whether to update the rerun file after this command.
.PARAMETER Cleanup
  Whether to clean up temporary files created on targets.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Transport
  Specify a default transport: docker, local, lxd, pcp, podman, remote, ssh, winrm.
  For more information, see 'bolt guide transports'.
.PARAMETER ConnectTimeout
  Connection timeout in seconds (defaults vary).
.PARAMETER TTY
  Request a pseudo TTY on targets that support it.
.PARAMETER NativeSsh
  Experimental. Whether to shell out to native SSH or use the net-ssh Ruby library.
.PARAMETER SshCommand
  Experimental. Executable to use instead of the net-ssh Ruby library.
.PARAMETER CopyCommand
  Experimental. Command to copy files to remote hosts if using native SSH.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Color
  Whether to show output in color.
.PARAMETER Trace
  Display error stack traces.
.PARAMETER Stream
  Stream output from scripts and commands to the console.
  Run with --no-verbose to prevent Bolt from displaying output
  a second time after the action is completed.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Noop
  See what changes Bolt will make without actually executing the changes.
.PARAMETER Execute
  Puppet manifest code to apply to the targets.
.PARAMETER CompileConcurrency
  Maximum number of simultaneous manifest block compiles (default: number of cores).
.PARAMETER HieraConfig
  Specify where to load Hiera config from (default: <project>/hiera.yaml).
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Invoke-BoltApply
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0, ParameterSetName='manifest')]
    [ValidateNotNullOrEmpty()]
    [Alias('mf')]
    [string]
    $Manifest,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Targets,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('q')]
    [string]
    $Query,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [ValidateSet("all", "failure", "success")]
    [string]
    $Rerun,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('u')]
    [string]
    $User,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('p')]
    [string]
    $Password,

    [Parameter()]
    [switch]
    $PasswordPrompt,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $PrivateKey,

    [Parameter()]
    [switch]
    $HostKeyCheck,

    [Parameter()]
    [switch]
    $Ssl,

    [Parameter()]
    [switch]
    $SslVerify,

    [Parameter()]
    [string]
    $RunAs,

    [Parameter()]
    [string]
    $SudoPassword,

    [Parameter()]
    [switch]
    $SudoPasswordPrompt,

    [Parameter()]
    [string]
    $SudoExecutable,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('c')]
    [string]
    $Concurrency,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]
    $SaveRerun,

    [Parameter()]
    [switch]
    $Cleanup,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidateSet("docker", "local", "lxd", "pcp", "podman", "remote", "ssh", "winrm")]
    [string]
    $Transport,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $ConnectTimeout,

    [Parameter()]
    [switch]
    $TTY,

    [Parameter()]
    [switch]
    $NativeSsh,

    [Parameter()]
    [string]
    $SshCommand,

    [Parameter()]
    [string]
    $CopyCommand,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]
    $Color,

    [Parameter()]
    [switch]
    $Trace,

    [Parameter()]
    [switch]
    $Stream,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [switch]
    $Noop,

    [Parameter(Mandatory=$true, Position=0, ParameterSetName='execute')]
    [Alias('e')]
    [string]
    $Execute,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $CompileConcurrency,

    [Parameter()]
    [string]
    $HieraConfig
  )

  $executionParams = @('apply')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt command run <command> {--targets TARGETS | --query QUERY | --rerun FILTER}
      [options]
.DESCRIPTION
  Run a command on the specified targets.
.PARAMETER Command
  The command to execute
.PARAMETER Targets
  Identifies the targets of the command.
  For more information, see 'bolt guide targets'.
.PARAMETER Query
  Query PuppetDB to determine the targets.
.PARAMETER Rerun
  Retry on targets from the last run.
  Available filters are 'all', 'failure', and 'success'.
.PARAMETER User
  User to authenticate as.
.PARAMETER Password
  Password to authenticate with.
.PARAMETER PasswordPrompt
  Prompt for user to input password.
.PARAMETER PrivateKey
  Path to private ssh key to authenticate with.
.PARAMETER HostKeyCheck
  Check host keys with SSH.
.PARAMETER Ssl
  Use SSL with WinRM.
.PARAMETER SslVerify
  Verify remote host SSL certificate with WinRM.
.PARAMETER RunAs
  User to run as using privilege escalation.
.PARAMETER SudoPassword
  Password for privilege escalation.
.PARAMETER SudoPasswordPrompt
  Prompt for user to input escalation password.
.PARAMETER SudoExecutable
  Experimental. Specify an executable for running as another user.
.PARAMETER Concurrency
  Maximum number of simultaneous connections.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER SaveRerun
  Whether to update the rerun file after this command.
.PARAMETER Cleanup
  Whether to clean up temporary files created on targets.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Transport
  Specify a default transport: docker, local, lxd, pcp, podman, remote, ssh, winrm.
  For more information, see 'bolt guide transports'.
.PARAMETER ConnectTimeout
  Connection timeout in seconds (defaults vary).
.PARAMETER TTY
  Request a pseudo TTY on targets that support it.
.PARAMETER NativeSsh
  Experimental. Whether to shell out to native SSH or use the net-ssh Ruby library.
.PARAMETER SshCommand
  Experimental. Executable to use instead of the net-ssh Ruby library.
.PARAMETER CopyCommand
  Experimental. Command to copy files to remote hosts if using native SSH.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Color
  Whether to show output in color.
.PARAMETER Trace
  Display error stack traces.
.PARAMETER Stream
  Stream output from scripts and commands to the console.
  Run with --no-verbose to prevent Bolt from displaying output
  a second time after the action is completed.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER EnvVar
  Environment variables to set on the target.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Invoke-BoltCommand
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('cm')]
    [string]
    $Command,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Targets,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('q')]
    [string]
    $Query,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [ValidateSet("all", "failure", "success")]
    [string]
    $Rerun,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('u')]
    [string]
    $User,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('p')]
    [string]
    $Password,

    [Parameter()]
    [switch]
    $PasswordPrompt,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $PrivateKey,

    [Parameter()]
    [switch]
    $HostKeyCheck,

    [Parameter()]
    [switch]
    $Ssl,

    [Parameter()]
    [switch]
    $SslVerify,

    [Parameter()]
    [string]
    $RunAs,

    [Parameter()]
    [string]
    $SudoPassword,

    [Parameter()]
    [switch]
    $SudoPasswordPrompt,

    [Parameter()]
    [string]
    $SudoExecutable,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('c')]
    [string]
    $Concurrency,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]
    $SaveRerun,

    [Parameter()]
    [switch]
    $Cleanup,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidateSet("docker", "local", "lxd", "pcp", "podman", "remote", "ssh", "winrm")]
    [string]
    $Transport,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $ConnectTimeout,

    [Parameter()]
    [switch]
    $TTY,

    [Parameter()]
    [switch]
    $NativeSsh,

    [Parameter()]
    [string]
    $SshCommand,

    [Parameter()]
    [string]
    $CopyCommand,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]
    $Color,

    [Parameter()]
    [switch]
    $Trace,

    [Parameter()]
    [switch]
    $Stream,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $EnvVar
  )

  $executionParams = @('command', 'run')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt file download <source> <destination> {--targets TARGETS | --query QUERY | --rerun FILTER}
      [options]
.DESCRIPTION
  Download a file or directory from one or more targets. Downloaded files and directories are saved to the a subdirectory matching the target's name under the destination directory. The destination directory is expanded relative to the downloads subdirectory of the project directory.
.PARAMETER Source
  The source file or directory to download
.PARAMETER Destination
  The destination to download to
.PARAMETER Targets
  Identifies the targets of the command.
  For more information, see 'bolt guide targets'.
.PARAMETER Query
  Query PuppetDB to determine the targets.
.PARAMETER Rerun
  Retry on targets from the last run.
  Available filters are 'all', 'failure', and 'success'.
.PARAMETER User
  User to authenticate as.
.PARAMETER Password
  Password to authenticate with.
.PARAMETER PasswordPrompt
  Prompt for user to input password.
.PARAMETER PrivateKey
  Path to private ssh key to authenticate with.
.PARAMETER HostKeyCheck
  Check host keys with SSH.
.PARAMETER Ssl
  Use SSL with WinRM.
.PARAMETER SslVerify
  Verify remote host SSL certificate with WinRM.
.PARAMETER RunAs
  User to run as using privilege escalation.
.PARAMETER SudoPassword
  Password for privilege escalation.
.PARAMETER SudoPasswordPrompt
  Prompt for user to input escalation password.
.PARAMETER SudoExecutable
  Experimental. Specify an executable for running as another user.
.PARAMETER Concurrency
  Maximum number of simultaneous connections.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER SaveRerun
  Whether to update the rerun file after this command.
.PARAMETER Cleanup
  Whether to clean up temporary files created on targets.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Transport
  Specify a default transport: docker, local, lxd, pcp, podman, remote, ssh, winrm.
  For more information, see 'bolt guide transports'.
.PARAMETER ConnectTimeout
  Connection timeout in seconds (defaults vary).
.PARAMETER TTY
  Request a pseudo TTY on targets that support it.
.PARAMETER NativeSsh
  Experimental. Whether to shell out to native SSH or use the net-ssh Ruby library.
.PARAMETER SshCommand
  Experimental. Executable to use instead of the net-ssh Ruby library.
.PARAMETER CopyCommand
  Experimental. Command to copy files to remote hosts if using native SSH.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Color
  Whether to show output in color.
.PARAMETER Trace
  Display error stack traces.
.PARAMETER Stream
  Stream output from scripts and commands to the console.
  Run with --no-verbose to prevent Bolt from displaying output
  a second time after the action is completed.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Receive-BoltFile
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('s')]
    [string]
    $Source,

    [Parameter(Mandatory=$true, Position=1)]
    [ValidateNotNullOrEmpty()]
    [Alias('d')]
    [string]
    $Destination,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Targets,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('q')]
    [string]
    $Query,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [ValidateSet("all", "failure", "success")]
    [string]
    $Rerun,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('u')]
    [string]
    $User,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('p')]
    [string]
    $Password,

    [Parameter()]
    [switch]
    $PasswordPrompt,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $PrivateKey,

    [Parameter()]
    [switch]
    $HostKeyCheck,

    [Parameter()]
    [switch]
    $Ssl,

    [Parameter()]
    [switch]
    $SslVerify,

    [Parameter()]
    [string]
    $RunAs,

    [Parameter()]
    [string]
    $SudoPassword,

    [Parameter()]
    [switch]
    $SudoPasswordPrompt,

    [Parameter()]
    [string]
    $SudoExecutable,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('c')]
    [string]
    $Concurrency,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]
    $SaveRerun,

    [Parameter()]
    [switch]
    $Cleanup,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidateSet("docker", "local", "lxd", "pcp", "podman", "remote", "ssh", "winrm")]
    [string]
    $Transport,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $ConnectTimeout,

    [Parameter()]
    [switch]
    $TTY,

    [Parameter()]
    [switch]
    $NativeSsh,

    [Parameter()]
    [string]
    $SshCommand,

    [Parameter()]
    [string]
    $CopyCommand,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]
    $Color,

    [Parameter()]
    [switch]
    $Trace,

    [Parameter()]
    [switch]
    $Stream,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache
  )

  $executionParams = @('file', 'download')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt file upload <source> <destination> {--targets TARGETS | --query QUERY | --rerun FILTER}
      [options]
.DESCRIPTION
  Upload a local file or directory.
.PARAMETER Source
  The source file or directory to upload
.PARAMETER Destination
  The destination to upload to
.PARAMETER Targets
  Identifies the targets of the command.
  For more information, see 'bolt guide targets'.
.PARAMETER Query
  Query PuppetDB to determine the targets.
.PARAMETER Rerun
  Retry on targets from the last run.
  Available filters are 'all', 'failure', and 'success'.
.PARAMETER User
  User to authenticate as.
.PARAMETER Password
  Password to authenticate with.
.PARAMETER PasswordPrompt
  Prompt for user to input password.
.PARAMETER PrivateKey
  Path to private ssh key to authenticate with.
.PARAMETER HostKeyCheck
  Check host keys with SSH.
.PARAMETER Ssl
  Use SSL with WinRM.
.PARAMETER SslVerify
  Verify remote host SSL certificate with WinRM.
.PARAMETER RunAs
  User to run as using privilege escalation.
.PARAMETER SudoPassword
  Password for privilege escalation.
.PARAMETER SudoPasswordPrompt
  Prompt for user to input escalation password.
.PARAMETER SudoExecutable
  Experimental. Specify an executable for running as another user.
.PARAMETER Concurrency
  Maximum number of simultaneous connections.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER SaveRerun
  Whether to update the rerun file after this command.
.PARAMETER Cleanup
  Whether to clean up temporary files created on targets.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Transport
  Specify a default transport: docker, local, lxd, pcp, podman, remote, ssh, winrm.
  For more information, see 'bolt guide transports'.
.PARAMETER ConnectTimeout
  Connection timeout in seconds (defaults vary).
.PARAMETER TTY
  Request a pseudo TTY on targets that support it.
.PARAMETER NativeSsh
  Experimental. Whether to shell out to native SSH or use the net-ssh Ruby library.
.PARAMETER SshCommand
  Experimental. Executable to use instead of the net-ssh Ruby library.
.PARAMETER CopyCommand
  Experimental. Command to copy files to remote hosts if using native SSH.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Color
  Whether to show output in color.
.PARAMETER Trace
  Display error stack traces.
.PARAMETER Stream
  Stream output from scripts and commands to the console.
  Run with --no-verbose to prevent Bolt from displaying output
  a second time after the action is completed.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Tmpdir
  The directory to upload and execute temporary files on the target.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Send-BoltFile
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('s')]
    [string]
    $Source,

    [Parameter(Mandatory=$true, Position=1)]
    [ValidateNotNullOrEmpty()]
    [Alias('d')]
    [string]
    $Destination,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Targets,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('q')]
    [string]
    $Query,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [ValidateSet("all", "failure", "success")]
    [string]
    $Rerun,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('u')]
    [string]
    $User,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('p')]
    [string]
    $Password,

    [Parameter()]
    [switch]
    $PasswordPrompt,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $PrivateKey,

    [Parameter()]
    [switch]
    $HostKeyCheck,

    [Parameter()]
    [switch]
    $Ssl,

    [Parameter()]
    [switch]
    $SslVerify,

    [Parameter()]
    [string]
    $RunAs,

    [Parameter()]
    [string]
    $SudoPassword,

    [Parameter()]
    [switch]
    $SudoPasswordPrompt,

    [Parameter()]
    [string]
    $SudoExecutable,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('c')]
    [string]
    $Concurrency,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]
    $SaveRerun,

    [Parameter()]
    [switch]
    $Cleanup,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidateSet("docker", "local", "lxd", "pcp", "podman", "remote", "ssh", "winrm")]
    [string]
    $Transport,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $ConnectTimeout,

    [Parameter()]
    [switch]
    $TTY,

    [Parameter()]
    [switch]
    $NativeSsh,

    [Parameter()]
    [string]
    $SshCommand,

    [Parameter()]
    [string]
    $CopyCommand,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]
    $Color,

    [Parameter()]
    [switch]
    $Trace,

    [Parameter()]
    [switch]
    $Stream,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Tmpdir
  )

  $executionParams = @('file', 'upload')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt group show [options]
.DESCRIPTION
  Show the list of groups in the inventory.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER Version
  Get the version of the bolt installation
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Get-BoltGroup
{
  [CmdletBinding()]
  param (
    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]$Version
  )

  if($version){
    return Get-BoltVersion
  }

  $executionParams = @('group', 'show')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt inventory show [options]
.DESCRIPTION
  Show the list of targets an action would run on. This command will list all targets in the project's inventory by default. To filter the targets in the list, use the --targets, --query, or --rerun options. To view detailed configuration and data for targets, use the --detail option. To learn more about the inventory run 'bolt guide inventory'.
.PARAMETER Targets
  Identifies the targets of the command.
  For more information, see 'bolt guide targets'.
.PARAMETER Query
  Query PuppetDB to determine the targets.
.PARAMETER Rerun
  Retry on targets from the last run.
  Available filters are 'all', 'failure', and 'success'.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER Detail
  Show resolved configuration for the targets.
.PARAMETER Version
  Get the version of the bolt installation
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Get-BoltInventory
{
  [CmdletBinding()]
  param (
    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Targets,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('q')]
    [string]
    $Query,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [ValidateSet("all", "failure", "success")]
    [string]
    $Rerun,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]
    $Detail,

    [Parameter()]
    [switch]$Version
  )

  if($version){
    return Get-BoltVersion
  }

  $executionParams = @('inventory', 'show')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt lookup <key> {--targets TARGETS | --query QUERY | --rerun FILTER}
      [options]
.DESCRIPTION
  Look up a value with Hiera.
.PARAMETER Key
  The key to look up
.PARAMETER Targets
  Identifies the targets of the command.
  For more information, see 'bolt guide targets'.
.PARAMETER Query
  Query PuppetDB to determine the targets.
.PARAMETER Rerun
  Retry on targets from the last run.
  Available filters are 'all', 'failure', and 'success'.
.PARAMETER User
  User to authenticate as.
.PARAMETER Password
  Password to authenticate with.
.PARAMETER PasswordPrompt
  Prompt for user to input password.
.PARAMETER PrivateKey
  Path to private ssh key to authenticate with.
.PARAMETER HostKeyCheck
  Check host keys with SSH.
.PARAMETER Ssl
  Use SSL with WinRM.
.PARAMETER SslVerify
  Verify remote host SSL certificate with WinRM.
.PARAMETER RunAs
  User to run as using privilege escalation.
.PARAMETER SudoPassword
  Password for privilege escalation.
.PARAMETER SudoPasswordPrompt
  Prompt for user to input escalation password.
.PARAMETER SudoExecutable
  Experimental. Specify an executable for running as another user.
.PARAMETER Concurrency
  Maximum number of simultaneous connections.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER SaveRerun
  Whether to update the rerun file after this command.
.PARAMETER Cleanup
  Whether to clean up temporary files created on targets.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Transport
  Specify a default transport: docker, local, lxd, pcp, podman, remote, ssh, winrm.
  For more information, see 'bolt guide transports'.
.PARAMETER ConnectTimeout
  Connection timeout in seconds (defaults vary).
.PARAMETER TTY
  Request a pseudo TTY on targets that support it.
.PARAMETER NativeSsh
  Experimental. Whether to shell out to native SSH or use the net-ssh Ruby library.
.PARAMETER SshCommand
  Experimental. Executable to use instead of the net-ssh Ruby library.
.PARAMETER CopyCommand
  Experimental. Command to copy files to remote hosts if using native SSH.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Color
  Whether to show output in color.
.PARAMETER Trace
  Display error stack traces.
.PARAMETER Stream
  Stream output from scripts and commands to the console.
  Run with --no-verbose to prevent Bolt from displaying output
  a second time after the action is completed.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER HieraConfig
  Specify where to load Hiera config from (default: <project>/hiera.yaml).
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Invoke-BoltLookup
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0, ParameterSetName='key')]
    [ValidateNotNullOrEmpty()]
    [Alias('k')]
    [string]
    $Key,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Targets,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('q')]
    [string]
    $Query,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [ValidateSet("all", "failure", "success")]
    [string]
    $Rerun,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('u')]
    [string]
    $User,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('p')]
    [string]
    $Password,

    [Parameter()]
    [switch]
    $PasswordPrompt,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $PrivateKey,

    [Parameter()]
    [switch]
    $HostKeyCheck,

    [Parameter()]
    [switch]
    $Ssl,

    [Parameter()]
    [switch]
    $SslVerify,

    [Parameter()]
    [string]
    $RunAs,

    [Parameter()]
    [string]
    $SudoPassword,

    [Parameter()]
    [switch]
    $SudoPasswordPrompt,

    [Parameter()]
    [string]
    $SudoExecutable,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('c')]
    [string]
    $Concurrency,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]
    $SaveRerun,

    [Parameter()]
    [switch]
    $Cleanup,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidateSet("docker", "local", "lxd", "pcp", "podman", "remote", "ssh", "winrm")]
    [string]
    $Transport,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $ConnectTimeout,

    [Parameter()]
    [switch]
    $TTY,

    [Parameter()]
    [switch]
    $NativeSsh,

    [Parameter()]
    [string]
    $SshCommand,

    [Parameter()]
    [string]
    $CopyCommand,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]
    $Color,

    [Parameter()]
    [switch]
    $Trace,

    [Parameter()]
    [switch]
    $Stream,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $HieraConfig
  )

  $executionParams = @('lookup')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt module add <module> [options]
.DESCRIPTION
  Add a module to the project. Module declarations are loaded from the project's configuration file. Bolt will automatically resolve all module dependencies, generate a Puppetfile, and install the modules.
.PARAMETER Module
  The name of the module to add to the Bolt project
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Add-BoltModule
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('md')]
    [string]
    $Module,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project
  )

  $executionParams = @('module', 'add')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt module generate-types [options]
.DESCRIPTION
  Generate type references to register in plans. To learn more about Bolt modules, run 'bolt guide module'.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Register-BoltModuleTypes
{
  [CmdletBinding()]
  param (
    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath
  )

  $executionParams = @('module', 'generate-types')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt module install [options]
.DESCRIPTION
  Install the project's modules. Module declarations are loaded from the project's configuration file. Bolt will automatically resolve all module dependencies, generate a Puppetfile, and install the modules.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Force
  Force a destructive action.
.PARAMETER Resolve
  Use --no-resolve to install modules listed in the Puppetfile without resolving modules configured
  in Bolt project configuration.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Install-BoltModule
{
  [CmdletBinding()]
  param (
    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [switch]
    $Force,

    [Parameter()]
    [switch]
    $Resolve
  )

  $executionParams = @('module', 'install')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt module show [options]
.DESCRIPTION
  List modules available to the Bolt project.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Version
  Get the version of the bolt installation
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Get-BoltModule
{
  [CmdletBinding()]
  param (
    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [switch]$Version
  )

  if($version){
    return Get-BoltVersion
  }

  $executionParams = @('module', 'show')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt plan show [plan name] [options]
.DESCRIPTION
  Show available plans and plan documentation. Omitting the name of a plan will display a list of plans available in the Bolt project. Providing the name of a plan will display detailed documentation for the plan, including a list of available parameters.
.PARAMETER Name
  The plan to show
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Filter
  Filter tasks and plans by a matching substring.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Version
  Get the version of the bolt installation
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Get-BoltPlan
{
  [CmdletBinding()]
  param (
    [Parameter(Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('n')]
    [string]
    $Name,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidatePattern('^[a-z0-9_:]+$')]
    [string]
    $Filter,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]$Version
  )

  if($version){
    return Get-BoltVersion
  }

  $executionParams = @('plan', 'show')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt plan run <plan name> [parameters] [options]
.DESCRIPTION
  Run a plan on the specified targets.
.PARAMETER Name
  The plan to run
.PARAMETER Targets
  Identifies the targets of the command.
  For more information, see 'bolt guide targets'.
.PARAMETER Query
  Query PuppetDB to determine the targets.
.PARAMETER Rerun
  Retry on targets from the last run.
  Available filters are 'all', 'failure', and 'success'.
.PARAMETER User
  User to authenticate as.
.PARAMETER Password
  Password to authenticate with.
.PARAMETER PasswordPrompt
  Prompt for user to input password.
.PARAMETER PrivateKey
  Path to private ssh key to authenticate with.
.PARAMETER HostKeyCheck
  Check host keys with SSH.
.PARAMETER Ssl
  Use SSL with WinRM.
.PARAMETER SslVerify
  Verify remote host SSL certificate with WinRM.
.PARAMETER RunAs
  User to run as using privilege escalation.
.PARAMETER SudoPassword
  Password for privilege escalation.
.PARAMETER SudoPasswordPrompt
  Prompt for user to input escalation password.
.PARAMETER SudoExecutable
  Experimental. Specify an executable for running as another user.
.PARAMETER Concurrency
  Maximum number of simultaneous connections.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER SaveRerun
  Whether to update the rerun file after this command.
.PARAMETER Cleanup
  Whether to clean up temporary files created on targets.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Transport
  Specify a default transport: docker, local, lxd, pcp, podman, remote, ssh, winrm.
  For more information, see 'bolt guide transports'.
.PARAMETER ConnectTimeout
  Connection timeout in seconds (defaults vary).
.PARAMETER TTY
  Request a pseudo TTY on targets that support it.
.PARAMETER NativeSsh
  Experimental. Whether to shell out to native SSH or use the net-ssh Ruby library.
.PARAMETER SshCommand
  Experimental. Executable to use instead of the net-ssh Ruby library.
.PARAMETER CopyCommand
  Experimental. Command to copy files to remote hosts if using native SSH.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Color
  Whether to show output in color.
.PARAMETER Trace
  Display error stack traces.
.PARAMETER Stream
  Stream output from scripts and commands to the console.
  Run with --no-verbose to prevent Bolt from displaying output
  a second time after the action is completed.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Params
  Parameters to a task or plan as json, a json file '@<file>', or on stdin '-'.
.PARAMETER CompileConcurrency
  Maximum number of simultaneous manifest block compiles (default: number of cores).
.PARAMETER Tmpdir
  The directory to upload and execute temporary files on the target.
.PARAMETER HieraConfig
  Specify where to load Hiera config from (default: <project>/hiera.yaml).
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Invoke-BoltPlan
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('n')]
    [string]
    $Name,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Targets,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('q')]
    [string]
    $Query,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [ValidateSet("all", "failure", "success")]
    [string]
    $Rerun,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('u')]
    [string]
    $User,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('p')]
    [string]
    $Password,

    [Parameter()]
    [switch]
    $PasswordPrompt,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $PrivateKey,

    [Parameter()]
    [switch]
    $HostKeyCheck,

    [Parameter()]
    [switch]
    $Ssl,

    [Parameter()]
    [switch]
    $SslVerify,

    [Parameter()]
    [string]
    $RunAs,

    [Parameter()]
    [string]
    $SudoPassword,

    [Parameter()]
    [switch]
    $SudoPasswordPrompt,

    [Parameter()]
    [string]
    $SudoExecutable,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('c')]
    [string]
    $Concurrency,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]
    $SaveRerun,

    [Parameter()]
    [switch]
    $Cleanup,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidateSet("docker", "local", "lxd", "pcp", "podman", "remote", "ssh", "winrm")]
    [string]
    $Transport,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $ConnectTimeout,

    [Parameter()]
    [switch]
    $TTY,

    [Parameter()]
    [switch]
    $NativeSsh,

    [Parameter()]
    [string]
    $SshCommand,

    [Parameter()]
    [string]
    $CopyCommand,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]
    $Color,

    [Parameter()]
    [switch]
    $Trace,

    [Parameter()]
    [switch]
    $Stream,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter(Position=1, ValueFromRemainingArguments=$true)]
    $Params,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $CompileConcurrency,

    [Parameter()]
    [string]
    $Tmpdir,

    [Parameter()]
    [string]
    $HieraConfig
  )

  $executionParams = @('plan', 'run')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt plan convert <plan name> [options]
.DESCRIPTION
  Convert a YAML plan to a Puppet language plan and print the converted plan to stdout. Converting a YAML plan might result in a plan that is syntactically correct but has different behavior. Always verify a converted plan's functionality. Note that the converted plan is not written to a file.
.PARAMETER Name
  The plan to convert
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Convert-BoltPlan
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('n')]
    [string]
    $Name,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath
  )

  $executionParams = @('plan', 'convert')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt plan new <plan name> [options]
.DESCRIPTION
  Create a new plan in the current project.
.PARAMETER Name
  The plan to create
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Pp
  Create a new Puppet language plan.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function New-BoltPlan
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('n')]
    [string]
    $Name,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [switch]
    $Pp
  )

  $executionParams = @('plan', 'new')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt project init [name] [options]
.DESCRIPTION
  Create a new Bolt project in the current working directory. Specify a name for the Bolt project. Defaults to the basename of the current working directory.
.PARAMETER Name
  The name of the Bolt project to create
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Modules
  A comma-separated list of modules to install from the Puppet Forge
  when initializing a project. Resolves and installs all dependencies.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function New-BoltProject
{
  [CmdletBinding()]
  param (
    [Parameter(Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('n')]
    [string]
    $Name,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    $Modules
  )

  $executionParams = @('project', 'init')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt project migrate [options]
.DESCRIPTION
  Migrate a Bolt project to use current best practices and the latest version of configuration files.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Update-BoltProject
{
  [CmdletBinding()]
  param (
    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile
  )

  $executionParams = @('project', 'migrate')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt script run <script> [arguments] {--targets TARGETS | --query QUERY | --rerun FILTER}
      [options]
.DESCRIPTION
  Run a script on the specified targets. Arguments passed to a script are passed literally and are not interpolated by the shell. Any arguments containing spaces or special characters should be quoted.
.PARAMETER Script
  The script to execute
.PARAMETER Arguments
  The arguments to the script
.PARAMETER Targets
  Identifies the targets of the command.
  For more information, see 'bolt guide targets'.
.PARAMETER Query
  Query PuppetDB to determine the targets.
.PARAMETER Rerun
  Retry on targets from the last run.
  Available filters are 'all', 'failure', and 'success'.
.PARAMETER User
  User to authenticate as.
.PARAMETER Password
  Password to authenticate with.
.PARAMETER PasswordPrompt
  Prompt for user to input password.
.PARAMETER PrivateKey
  Path to private ssh key to authenticate with.
.PARAMETER HostKeyCheck
  Check host keys with SSH.
.PARAMETER Ssl
  Use SSL with WinRM.
.PARAMETER SslVerify
  Verify remote host SSL certificate with WinRM.
.PARAMETER RunAs
  User to run as using privilege escalation.
.PARAMETER SudoPassword
  Password for privilege escalation.
.PARAMETER SudoPasswordPrompt
  Prompt for user to input escalation password.
.PARAMETER SudoExecutable
  Experimental. Specify an executable for running as another user.
.PARAMETER Concurrency
  Maximum number of simultaneous connections.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER SaveRerun
  Whether to update the rerun file after this command.
.PARAMETER Cleanup
  Whether to clean up temporary files created on targets.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Transport
  Specify a default transport: docker, local, lxd, pcp, podman, remote, ssh, winrm.
  For more information, see 'bolt guide transports'.
.PARAMETER ConnectTimeout
  Connection timeout in seconds (defaults vary).
.PARAMETER TTY
  Request a pseudo TTY on targets that support it.
.PARAMETER NativeSsh
  Experimental. Whether to shell out to native SSH or use the net-ssh Ruby library.
.PARAMETER SshCommand
  Experimental. Executable to use instead of the net-ssh Ruby library.
.PARAMETER CopyCommand
  Experimental. Command to copy files to remote hosts if using native SSH.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Color
  Whether to show output in color.
.PARAMETER Trace
  Display error stack traces.
.PARAMETER Stream
  Stream output from scripts and commands to the console.
  Run with --no-verbose to prevent Bolt from displaying output
  a second time after the action is completed.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Tmpdir
  The directory to upload and execute temporary files on the target.
.PARAMETER EnvVar
  Environment variables to set on the target.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Invoke-BoltScript
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('s')]
    [string]
    $Script,

    [Parameter(Position=1)]
    [Alias('a')]
    [string]
    $Arguments,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Targets,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('q')]
    [string]
    $Query,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [ValidateSet("all", "failure", "success")]
    [string]
    $Rerun,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('u')]
    [string]
    $User,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('p')]
    [string]
    $Password,

    [Parameter()]
    [switch]
    $PasswordPrompt,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $PrivateKey,

    [Parameter()]
    [switch]
    $HostKeyCheck,

    [Parameter()]
    [switch]
    $Ssl,

    [Parameter()]
    [switch]
    $SslVerify,

    [Parameter()]
    [string]
    $RunAs,

    [Parameter()]
    [string]
    $SudoPassword,

    [Parameter()]
    [switch]
    $SudoPasswordPrompt,

    [Parameter()]
    [string]
    $SudoExecutable,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('c')]
    [string]
    $Concurrency,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]
    $SaveRerun,

    [Parameter()]
    [switch]
    $Cleanup,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidateSet("docker", "local", "lxd", "pcp", "podman", "remote", "ssh", "winrm")]
    [string]
    $Transport,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $ConnectTimeout,

    [Parameter()]
    [switch]
    $TTY,

    [Parameter()]
    [switch]
    $NativeSsh,

    [Parameter()]
    [string]
    $SshCommand,

    [Parameter()]
    [string]
    $CopyCommand,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]
    $Color,

    [Parameter()]
    [switch]
    $Trace,

    [Parameter()]
    [switch]
    $Stream,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Tmpdir,

    [Parameter()]
    [string]
    $EnvVar
  )

  $executionParams = @('script', 'run')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt secret encrypt <plaintext> [options]
.DESCRIPTION
  Encrypt a value.
.PARAMETER Text
  The text to encrypt
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Plugin
  Select the plugin to use.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Protect-BoltSecret
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Text,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [string]
    $Plugin
  )

  $executionParams = @('secret', 'encrypt')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt secret decrypt <ciphertext> [options]
.DESCRIPTION
  Decrypt a value.
.PARAMETER Text
  The text to decrypt
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Plugin
  Select the plugin to use.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Unprotect-BoltSecret
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Text,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [string]
    $Plugin
  )

  $executionParams = @('secret', 'decrypt')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt secret createkeys [options]
.DESCRIPTION
  Create new encryption keys.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Plugin
  Select the plugin to use.
.PARAMETER Force
  Force a destructive action.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function New-BoltSecretKey
{
  [CmdletBinding()]
  param (
    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [string]
    $Plugin,

    [Parameter()]
    [switch]
    $Force
  )

  $executionParams = @('secret', 'createkeys')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt task show [task name] [options]
.DESCRIPTION
  Show available tasks and task documentation. Omitting the name of a task will display a list of tasks available in the Bolt project. Providing the name of a task will display detailed documentation for the task, including a list of available parameters.
.PARAMETER Name
  The task to show
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Filter
  Filter tasks and plans by a matching substring.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Version
  Get the version of the bolt installation
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Get-BoltTask
{
  [CmdletBinding()]
  param (
    [Parameter(Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('n')]
    [string]
    $Name,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidatePattern('^[a-z0-9_:]+$')]
    [string]
    $Filter,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]$Version
  )

  if($version){
    return Get-BoltVersion
  }

  $executionParams = @('task', 'show')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}

<#
.SYNOPSIS
  bolt task run <task name> [parameters] {--targets TARGETS | --query QUERY | --rerun FILTER}
      [options]
.DESCRIPTION
  Run a task on the specified targets. Parameters take the form parameter=value.
.PARAMETER Name
  The task to run
.PARAMETER Targets
  Identifies the targets of the command.
  For more information, see 'bolt guide targets'.
.PARAMETER Query
  Query PuppetDB to determine the targets.
.PARAMETER Rerun
  Retry on targets from the last run.
  Available filters are 'all', 'failure', and 'success'.
.PARAMETER User
  User to authenticate as.
.PARAMETER Password
  Password to authenticate with.
.PARAMETER PasswordPrompt
  Prompt for user to input password.
.PARAMETER PrivateKey
  Path to private ssh key to authenticate with.
.PARAMETER HostKeyCheck
  Check host keys with SSH.
.PARAMETER Ssl
  Use SSL with WinRM.
.PARAMETER SslVerify
  Verify remote host SSL certificate with WinRM.
.PARAMETER RunAs
  User to run as using privilege escalation.
.PARAMETER SudoPassword
  Password for privilege escalation.
.PARAMETER SudoPasswordPrompt
  Prompt for user to input escalation password.
.PARAMETER SudoExecutable
  Experimental. Specify an executable for running as another user.
.PARAMETER Concurrency
  Maximum number of simultaneous connections.
.PARAMETER Inventoryfile
  Specify where to load inventory from (default: <project>/inventory.yaml).
.PARAMETER SaveRerun
  Whether to update the rerun file after this command.
.PARAMETER Cleanup
  Whether to clean up temporary files created on targets.
.PARAMETER Project
  Path to load the Bolt project from (default: autodiscovered from current dir).
.PARAMETER Modulepath
  List of directories containing modules, separated by ';'
  Directories are case-sensitive.
.PARAMETER Transport
  Specify a default transport: docker, local, lxd, pcp, podman, remote, ssh, winrm.
  For more information, see 'bolt guide transports'.
.PARAMETER ConnectTimeout
  Connection timeout in seconds (defaults vary).
.PARAMETER TTY
  Request a pseudo TTY on targets that support it.
.PARAMETER NativeSsh
  Experimental. Whether to shell out to native SSH or use the net-ssh Ruby library.
.PARAMETER SshCommand
  Experimental. Executable to use instead of the net-ssh Ruby library.
.PARAMETER CopyCommand
  Experimental. Command to copy files to remote hosts if using native SSH.
.PARAMETER Format
  Output format to use: human, json, or rainbow.
.PARAMETER Color
  Whether to show output in color.
.PARAMETER Trace
  Display error stack traces.
.PARAMETER Stream
  Stream output from scripts and commands to the console.
  Run with --no-verbose to prevent Bolt from displaying output
  a second time after the action is completed.
.PARAMETER LogLevel
  Set the log level for the console. Available options are
  trace, debug, info, warn, error, fatal, any.
.PARAMETER ClearCache
  Clear plugin cache before executing.
.PARAMETER Params
  Parameters to a task or plan as json, a json file '@<file>', or on stdin '-'.
.PARAMETER Tmpdir
  The directory to upload and execute temporary files on the target.
.PARAMETER Noop
  See what changes Bolt will make without actually executing the changes.
.LINK
  https://puppet.com/products/bolt
.LINK
  https://puppet.com/docs/bolt/latest/bolt_command_reference.html
#>

function Invoke-BoltTask
{
  [CmdletBinding()]
  param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateNotNullOrEmpty()]
    [Alias('n')]
    [string]
    $Name,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('t')]
    [string]
    $Targets,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('q')]
    [string]
    $Query,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [ValidateSet("all", "failure", "success")]
    [string]
    $Rerun,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('u')]
    [string]
    $User,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('p')]
    [string]
    $Password,

    [Parameter()]
    [switch]
    $PasswordPrompt,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $PrivateKey,

    [Parameter()]
    [switch]
    $HostKeyCheck,

    [Parameter()]
    [switch]
    $Ssl,

    [Parameter()]
    [switch]
    $SslVerify,

    [Parameter()]
    [string]
    $RunAs,

    [Parameter()]
    [string]
    $SudoPassword,

    [Parameter()]
    [switch]
    $SudoPasswordPrompt,

    [Parameter()]
    [string]
    $SudoExecutable,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('c')]
    [string]
    $Concurrency,

    [Parameter()]
    [Alias('i')]
    [string]
    $Inventoryfile,

    [Parameter()]
    [switch]
    $SaveRerun,

    [Parameter()]
    [switch]
    $Cleanup,

    [Parameter()]
    [string]
    $Project,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [Alias('m')]
    [string]
    $Modulepath,

    [Parameter()]
    [ValidateSet("docker", "local", "lxd", "pcp", "podman", "remote", "ssh", "winrm")]
    [string]
    $Transport,

    [Parameter()]
    [ValidateNotNullOrEmpty()]
    [string]
    $ConnectTimeout,

    [Parameter()]
    [switch]
    $TTY,

    [Parameter()]
    [switch]
    $NativeSsh,

    [Parameter()]
    [string]
    $SshCommand,

    [Parameter()]
    [string]
    $CopyCommand,

    [Parameter()]
    [ValidateSet("human", "json", "rainbow")]
    [string]
    $Format,

    [Parameter()]
    [switch]
    $Color,

    [Parameter()]
    [switch]
    $Trace,

    [Parameter()]
    [switch]
    $Stream,

    [Parameter()]
    [ValidateSet("trace", "debug", "info", "notice", "warn", "error", "fatal", "any")]
    [string]
    $LogLevel,

    [Parameter()]
    [switch]
    $ClearCache,

    [Parameter(Position=1, ValueFromRemainingArguments=$true)]
    $Params,

    [Parameter()]
    [string]
    $Tmpdir,

    [Parameter()]
    [switch]
    $Noop
  )

  $executionParams = @('task', 'run')

  $executionParams = $executionParams + (Get-BoltCommandline -parameterHash $PSBoundParameters -mapping $mapping)

  $result = Invoke-BoltCommandline $executionParams

  Write-Output $result

}