ChefDK on Windows Workstations

[edit on GitHub]

This guide details some of the common considerations that come into play when using the Chef Development Kit on Windows. Download the ChefDK by following the installation instructions on Installing the ChefDK.


A workstation is a computer running the Chef Development Kit (Chef DK) that is used to author cookbooks, interact with the Chef server, and interact with nodes.

The workstation is where users do most of their work, including:

  • Developing and testing cookbooks and recipes
  • Testing Chef code
  • Keeping the Chef repository synchronized with version source control
  • Configuring organizational policy, including defining roles and environments, and ensuring that critical data is stored in data bags
  • Interacting with nodes, as (or when) required, such as performing a bootstrap operation

Installing ChefDK on Windows

Configure Environment

You can use the chef shell-init command with Windows PowerShell to add the appropriate variables to your environment.

To try it in your current session:

chef shell-init powershell | Invoke-Expression

To enable it permanently:

"chef shell-init powershell | Invoke-Expression" >> $PROFILE

If $PROFILE does not exist, continue to the next section.

Create a Profile

On new Windows machines, commands cannot be appended to $PROFILE if the folder does not exist, or if there is a new user profile. This will result in an error similar to the following:

PS C:\Users\Stuart> "chef shell-init powershell | Invoke-Expression" >> $PROFILE
out-file : Could not find a part of the path
At line:1 char:1
+ "chef shell-init powershell | Invoke-Expression" >> $PROFILE
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Out-File], DirectoryNotFoundException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

In this situation, run the following chef shell-init command instead:

if(Test-Path $PROFILE){ chef shell-init powershell | Add-Content $PROFILE } else { New-Item -Force -ItemType File $PROFILE; chef shell-init powershell | Add-Content $PROFILE }

Set the Execution Policy

On new Windows machines, PowerShell scripts will not work until an administrator runs the following command:

Set-ExecutionPolicy RemoteSigned

Spaces and Directories

Directories that are used by Chef on Windows cannot have spaces. For example, C:\Users\Steven Danno will not work, but C:\Users\StevenDanno will. Because of this, the knife supermarket install subcommand will fail if the directory contains a space.

Top-level Directory Names

Windows will throw errors when path name lengths are too long. For this reason, it’s often helpful to use a very short top-level directory, much like what is done in UNIX and Linux. For example, Chef uses /opt/ to install the Chef development kit on macOS. A similar approach can be done on Microsoft Windows, by creating a top-level directory with a short name. For example: C:\chef.