github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/website/source/docs/provisioners/powershell.html.md (about)

     1  ---
     2  description: |
     3      The shell Packer provisioner provisions machines built by Packer using shell
     4      scripts. Shell provisioning is the easiest way to get software installed and
     5      configured on a machine.
     6  layout: docs
     7  page_title: 'PowerShell - Provisioners'
     8  sidebar_current: 'docs-provisioners-powershell'
     9  ---
    10  
    11  # PowerShell Provisioner
    12  
    13  Type: `powershell`
    14  
    15  The PowerShell Packer provisioner runs PowerShell scripts on Windows machines.
    16  It assumes that the communicator in use is WinRM.
    17  
    18  ## Basic Example
    19  
    20  The example below is fully functional.
    21  
    22  ``` json
    23  {
    24    "type": "powershell",
    25    "inline": ["dir c:\\"]
    26  }
    27  ```
    28  
    29  ## Configuration Reference
    30  
    31  The reference of available configuration options is listed below. The only
    32  required element is either "inline" or "script". Every other option is optional.
    33  
    34  Exactly *one* of the following is required:
    35  
    36  -   `inline` (array of strings) - This is an array of commands to execute. The
    37      commands are concatenated by newlines and turned into a single file, so they
    38      are all executed within the same context. This allows you to change
    39      directories in one command and use something in the directory in the next
    40      and so on. Inline scripts are the easiest way to pull off simple tasks
    41      within the machine.
    42  
    43  -   `script` (string) - The path to a script to upload and execute in
    44      the machine. This path can be absolute or relative. If it is relative, it is
    45      relative to the working directory when Packer is executed.
    46  
    47  -   `scripts` (array of strings) - An array of scripts to execute. The scripts
    48      will be uploaded and executed in the order specified. Each script is
    49      executed in isolation, so state such as variables from one script won't
    50      carry on to the next.
    51  
    52  Optional parameters:
    53  
    54  -   `binary` (boolean) - If true, specifies that the script(s) are binary files,
    55      and Packer should therefore not convert Windows line endings to Unix line
    56      endings (if there are any). By default this is false.
    57  
    58  -   `elevated_execute_command` (string) - The command to use to execute the elevated
    59      script. By default this is as follows:
    60  
    61      ``` powershell
    62      powershell -executionpolicy bypass "& { if (Test-Path variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'};. {{.Vars}}; &'{{.Path}}'; exit $LastExitCode }"
    63      ```
    64  
    65      The value of this is treated as [configuration
    66      template](/docs/templates/engine.html). There are two
    67      available variables: `Path`, which is the path to the script to run, and
    68      `Vars`, which is the location of a temp file containing the list of `environment_vars`, if configured.
    69  
    70  -   `environment_vars` (array of strings) - An array of key/value pairs to
    71      inject prior to the execute\_command. The format should be `key=value`.
    72      Packer injects some environmental variables by default into the environment,
    73      as well, which are covered in the section below.
    74  
    75  -   `execute_command` (string) - The command to use to execute the script. By
    76      default this is as follows:
    77  
    78      ``` powershell
    79      powershell -executionpolicy bypass "& { if (Test-Path variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'};{{.Vars}}&'{{.Path}}';exit $LastExitCode }"
    80      ```
    81  
    82      The value of this is treated as [configuration
    83      template](/docs/templates/engine.html). There are two
    84      available variables: `Path`, which is the path to the script to run, and
    85      `Vars`, which is the list of `environment_vars`, if configured.
    86  
    87  -   `elevated_user` and `elevated_password` (string) - If specified, the
    88      PowerShell script will be run with elevated privileges using the given
    89      Windows user.
    90  
    91  -   `remote_path` (string) - The path where the script will be uploaded to in
    92      the machine. This defaults to "c:/Windows/Temp/script.ps1". This value must be a
    93      writable location and any parent directories must already exist.
    94  
    95  -   `start_retry_timeout` (string) - The amount of time to attempt to *start*
    96      the remote process. By default this is "5m" or 5 minutes. This setting
    97      exists in order to deal with times when SSH may restart, such as a
    98      system reboot. Set this to a higher value if reboots take a longer amount
    99      of time.
   100  
   101  -   `valid_exit_codes` (list of ints) - Valid exit codes for the script. By
   102      default this is just 0.
   103  
   104  ## Default Environmental Variables
   105  
   106  In addition to being able to specify custom environmental variables using the
   107  `environment_vars` configuration, the provisioner automatically defines certain
   108  commonly useful environmental variables:
   109  
   110  -   `PACKER_BUILD_NAME` is set to the name of the build that Packer is running.
   111      This is most useful when Packer is making multiple builds and you want to
   112      distinguish them slightly from a common provisioning script.
   113  
   114  -   `PACKER_BUILDER_TYPE` is the type of the builder that was used to create the
   115      machine that the script is running on. This is useful if you want to run
   116      only certain parts of the script on systems built with certain builders.
   117  
   118  -   `PACKER_HTTP_ADDR` If using a builder that provides an http server for file
   119      transfer (such as hyperv, parallels, qemu, virtualbox, and vmware), this
   120      will be set to the address. You can use this address in your provisioner to
   121      download large files over http. This may be useful if you're experiencing
   122      slower speeds using the default file provisioner. A file provisioner using
   123      the `winrm` communicator may experience these types of difficulties.