Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status

RSS

powershell (59) Versions 3.1.0

Installs/Configures PowerShell on the Windows platform

Policyfile
Berkshelf
Knife
cookbook 'powershell', '= 3.1.0', :supermarket
cookbook 'powershell', '= 3.1.0'
knife supermarket install powershell
knife supermarket download powershell
README
Dependencies
Changelog
Quality 100%

Powershell Cookbook

Installs and configures PowerShell 2.0, 3.0, 4.0 or 5.0.

For users of Chef 10 without the powershell_script built-in resource, this cookbook also includes a resource/provider for executing scripts using the PowerShell interpreter.

Requirements

Platforms

Not every version of Windows supports every version of Powershell. The following table illustrates Powershell support across the Windows family. Included means that the base installation of the operating system includes the indicated version of Powershell.

<table>
<tr>
<th>Windows Version</th>
<th>PowerShell 2.0</th>
<th>PowerShell 3.0</th>
<th>PowerShell 4.0</th>
<th>PowerShell 5.0</th>
</tr>
<tr>
<td>Windows XP</td>
<td>Supported</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Windows Server 2003 / 2003 R2</td>
<td>Supported</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Windows Server 2008 / Vista</td>
<td>Supported</td>
<td>Supported</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Windows Server 2008 R2</td>
<td>Supported</td>
<td>Included</td>
<td>Supported</td>
<td></td>
</tr>
<tr>
<td>Windows Server 2012 / Windows 8</td>
<td>Supported</td>
<td>Included</td>
<td>Supported</td>
<td></td>
</tr>
<tr>
<td>Windows Server 2012R2 / Windows 8.1</td>
<td></td>
<td></td>
<td>Included</td>
<td>Supported</td>
</tr>
</table>

Cookbooks

  • windows

PowerShell also requires the appropriate version of the Microsoft .NET Framework to be installed, if the operating system does not ship with that version. The following community cookbooks are used to install the correct version of the .NET Framework:

  • ms_dotnet2
  • ms_dotnet4
  • ms_dotnet45

Resource/Provider

Note: In Chef 11, use the built-in powershell_script resource.

powershell

Execute a script using the PowerShell interpreter (much like the script resources for bash, csh, perl, python and ruby). A temporary file is created and executed like other script resources, rather than run inline. By their nature, Script resources are not idempotent, as they are completely up to the user's imagination. Use the not_if or only_if meta parameters to guard the resource for idempotence.

Actions

  • :run: run the script

Attribute Parameters

  • command: name attribute. Name of the command to execute.
  • code: quoted string of code to execute.
  • creates: a file this command creates - if the file exists, the command will not be run.
  • cwd: current working directory to run the command from.
  • flags: command line flags to pass to the interpreter when invoking.
  • environment: A hash of environment variables to set before running this command.
  • user: A user name or user ID that we should change to before running this command.
  • group: A group name or group ID that we should change to before running this command.
  • returns: The return value of the command (may be an array of accepted values). This resource raises an exception if the return value(s) do not match.
  • timeout: How many seconds to let the command run before timing it out.

Examples

# change the computer's hostname
powershell "rename hostname" do
  code <<-EOH
  $computer_name = Get-Content env:computername
  $new_name = 'test-hostname'
  $sysInfo = Get-WmiObject -Class Win32_ComputerSystem
  $sysInfo.Rename($new_name)
  EOH
end
# write out to an interpolated path
powershell "write-to-interpolated-path" do
  code <<-EOH
  $stream = [System.IO.StreamWriter] "#{Chef::Config[:file_cache_path]}/powershell-test.txt"
  $stream.WriteLine("In #{Chef::Config[:file_cache_path]}...word.")
  $stream.close()
  EOH
end
# use the change working directory attribute
powershell "cwd-then-write" do
  cwd Chef::Config[:file_cache_path]
  code <<-EOH
  $stream = [System.IO.StreamWriter] "C:/powershell-test2.txt"
  $pwd = pwd
  $stream.WriteLine("This is the contents of: $pwd")
  $dirs = dir
  foreach ($dir in $dirs) {
    $stream.WriteLine($dir.fullname)
  }
  $stream.close()
  EOH
end
# cwd to a winodws env variable
powershell "cwd-to-win-env-var" do
  cwd ENV['TEMP']
  code <<-EOH
  $stream = [System.IO.StreamWriter] "./temp-write-from-chef.txt"
  $stream.WriteLine("chef on windows rox yo!")
  $stream.close()
  EOH
end
# pass an env var to script
powershell "read-env-var" do
  cwd Chef::Config[:file_cache_path]
  environment ({'foo' => 'BAZ'})
  code <<-EOH
  $stream = [System.IO.StreamWriter] "./test-read-env-var.txt"
  $stream.WriteLine("FOO is $env:foo")
  $stream.close()
  EOH
end

powershell_module

Installs or uninstalls a Powershell module

Actions

  • :install: install the powershell module
  • :uninstall: uninstall the powershell module

Attribute Parameters

  • name: name attribute. Name of the module to install or uninstall.
  • source: quoted string of Local directory path(Not zipfile) or URL for the zipped module folder.
  • package_name: quoted string of name of the module to install or uninstall.
  • destination: location where module should be installed

Examples

# Install module from local directory path
# change the package_name and source
powershell_module "PsUrl" do
  package_name "PsUrl"
  source "C:\\PsUrl"
end
# Install from URL of zipped module folder
powershell_module "posh-git" do
  package_name "posh-git"
  source "https://github.com/dahlbyk/posh-git/zipball/master"
end
# change the package_name
powershell_module "Uninstall PsUrl" do
  package_name "PsUrl"
  action :uninstall
end
# Install without using 'source' attribute
powershell_module "https://github.com/dahlbyk/posh-git/zipball/master" do
  package_name "posh-git"  
end

Mixin

The Chef::Mixin::PowershellOut mixin has been moved to the windows cookbook.

Usage

Note: The installation may require a restart of the node being configured before PowerShell can be used.

default

The default recipe does nothing.

powershell2

Include the powershell2 recipe in a run list, to ensure PowerShell 2.0 is installed.

On the following versions of Windows the PowerShell 2.0 package will be downloaded from Microsoft and installed:

  • Windows XP
  • Windows Server 2003
  • Windows Server 2008
  • Windows Vista

On the following versions of Windows, PowerShell 2.0 is present and must just be enabled:

  • Windows 7
  • Windows Server 2008 R2
  • Windows Server 2008 R2 Core

powershell3

Include the powershell3 recipe in a run list, to install PowerShell 3.0 is installed on applicable platforms. If a platform is not supported or if it already includes PowerShell 3.0, an exception will be raised.

powershell4

Include the powershell4 recipe in a run list, to install PowerShell 4.0 is installed on applicable platforms. If a platform is not supported or if it already includes PowerShell 4.0, an exception will be raised.

powershell5

Note: Windows Management Framework 5 is in preview.

Include the powershell5 recipe in a run list, to install PowerShell 5.0 is installed on applicable platforms. If a platform is not supported or if it already includes PowerShell 5.0, an exception will be raised.

References

License & Authors

Copyright:: 2011-2014, Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Dependent cookbooks

windows >= 1.2.8
ms_dotnet45 >= 0.0.0
ms_dotnet4 >= 0.0.0
ms_dotnet2 >= 0.0.0
chef_handler >= 0.0.0

Contingent cookbooks

chocolatey Applicable Versions
chz-firewall Applicable Versions
dsc2 Applicable Versions
filebeat Applicable Versions
helios Applicable Versions
network_interfaces_v2 Applicable Versions
nuget_dsc Applicable Versions
powercli_install Applicable Versions
sitecore Applicable Versions
topbeat Applicable Versions
windows Applicable Versions
winrm Applicable Versions
winstaller Applicable Versions
wsus-client Applicable Versions
wsus-server Applicable Versions

powershell Cookbook CHANGELOG

This file is used to list changes made in each version of the powershell cookbook.

v3.1.0 (2015-04-27)

v3.0.7 (2014-07-16)

  • Truly fix broken cookbook upload

v3.0.6 (2014-07-15)

  • Fixes a broken cookbook upload

v3.0.5 (2014-07-11)

  • Use attributes for bits_4 rather than hardcoding (@jmauro)
  • Update to Powershell 5.0 May 2014 preview

v3.0.4 (2014-05-09)

  • [COOK-4634] - Implement Powershell 5.0 (preview)
  • [COOK-4638] - PowerShell 4.0 install failing on clean Windows 2008 R2 install.

v3.0.2 (2014-04-23)

  • [COOK-4480] - Fix download URL for Windows6.0-KB968930-x86.msu

v3.0.0 (2014-02-05)

  • [COOK-4130] - Refactor Powershell cookbook to allow installing PowerShell 3.0 and 4.0
  • [COOK-4132] - Warn user if they are still using these LWRPs in Chef 11.6.x

v2.0.0 (2014-01-03)

[COOK-4168] Circular dep on powershell - moving powershell libraries into windows. removing dependency on powershell

v1.1.2

Bug

  • COOK-3000 - Fix typo that prevented module loading

v1.1.0

Bug

  • [COOK-2974]: powershell cookbook has foodcritic failures

Improvement

  • [COOK-2586]: Create a powershell_out mixin to be able to use in LWRPs for calling powershell

v1.0.8

  • [COOK-1834] - fix broken notifies

v1.0.6

  • Refactor the powershell resource from a core-Chef monkey-patch into a proper LWRP.
  • Take advantage of native Win32 support for cwd and environment in Chef 0.10.8+.
  • [COOK-630] force powershell scripts to terminate immediately and return an error code on failure
  • ensure more sane default options are set on PowerShell process

v1.0.4

  • [COOK-988] - Powershell never exists on the powershell resource

v1.0.2

  • always reference powershell.exe in a fully qualified way in case PATH
  • move download url and checksums to attribute file
  • massive refactor of default recipe...leverages windows_package and version helper provided by recent windows cookbook updates

v1.0.1

  • [COOK-581] force 64-bit powershell process from 32-bit ruby processes

v1.0.0

  • initial release

Foodcritic Metric
            

3.1.0 passed this metric