4 changes: 4 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fixtures:
forge_modules:
symlinks:
"powershell": "#{source_dir}"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pkg/
Gemfile.lock
Gemfile.local
vendor/
spec/fixtures/
log/
junit/
Expand Down
27 changes: 11 additions & 16 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@
env: PUPPET_GEM_VERSION="3.0.0"
Gemfile:
supports_windows: true
required:
':development':
- gem: rake
- gem: rspec
version: '~>3.0.0'
- gem: puppet-lint
- gem: puppetlabs_spec_helper
version: '~>0.10.3'
- gem: puppet_facts
- gem: mocha
version: '~>0.10.5'
':system_tests':
- gem: beaker
- gem: beaker-rspec
- gem: beaker-puppet_install_helper
Rakefile:
unmanaged: true
spec/spec_helper.rb:
Expand All @@ -30,4 +15,14 @@ appveyor.yml:
- PUPPET_GEM_VERSION: 3.0.0
RUBY_VER: 193
test_script:
- 'bundle exec rspec spec/unit -fd -b'
- 'bundle exec rspec spec/unit spec/integration -fd -b'
MAINTAINERS.md:
maintainers:
- "Puppet Windows Team `windows |at| puppet |dot| com`"
NOTICE:
copyright_holders:
- name: 'Josh Cooper, original author'
begin: 2013
- name: 'Puppet, Inc.'
begin: 2013
end: 'latest'
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ matrix:
env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="3.0.0"
allow_failures:
- rvm: 2.1.5
env: PUPPET_GEM_VERSION="~> 4.0"
notifications:
email: false
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
##Supported Release 1.0.6
##2015-05-17 - Supported Release 2.0.0
###Summary

Major release with performance improvements

Removed support for Windows Server 2003

###Features
- Major performance improvement by sharing a single powershell session instead of creating a new powershell session per command
- Security improvement as scripts are not stored on the filesystem temporarily

###Bug Fixes
- Updated test suites with later versions
- Documentation cleanup

##2015-12-08 - Supported Release 1.0.6
###Summary

Small release for support of newer PE versions.
Expand Down
8 changes: 3 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Checklist (and a short version for the impatient)

- Make sure you have a [GitHub account](https://github.com/join)

- [Create a ticket](https://tickets.puppetlabs.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppetlabs.com/browse/) you are patching for.
- [Create a ticket](https://tickets.puppet.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppet.com/browse/) you are patching for.

* Preferred method:

Expand Down Expand Up @@ -208,11 +208,9 @@ review.
Additional Resources
====================

* [Getting additional help](http://puppetlabs.com/community/get-help)
* [Getting additional help](http://puppet.com/community/get-help)

* [Writing tests](http://projects.puppetlabs.com/projects/puppet/wiki/Development_Writing_Tests)

* [Patchwork](https://patchwork.puppetlabs.com)
* [Writing tests](https://docs.puppet.com/guides/module_guides/bgtm.html#step-three-module-testing)

* [General GitHub documentation](http://help.github.com/)

Expand Down
36 changes: 30 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@ def location_for(place_or_version, fake_version = nil)
end
end

# The following gems are not included by default as they require DevKit on Windows.
# You should probably include them in a Gemfile.local or a ~/.gemfile
#gem 'pry' #this may already be included in the gemfile
#gem 'pry-stack_explorer', :require => false
#if RUBY_VERSION =~ /^2/
# gem 'pry-byebug'
#else
# gem 'pry-debugger'
#end

group :development do
gem 'rake', :require => false
gem 'rspec', '~>3.0.0', :require => false
gem 'rspec', '~>3.0', :require => false
gem 'puppet-lint', :require => false
gem 'puppetlabs_spec_helper', '~>0.10.3', :require => false
gem 'puppet_facts', :require => false
gem 'mocha', '~>0.10.5', :require => false
gem 'pry', :require => false
end

group :system_tests do
gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '~> 2.18')
gem 'beaker-rspec', *location_for(ENV['BEAKER_RSPEC_VERSION'] || '~> 5.1')
gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '~> 2.20')
gem 'beaker-puppet_install_helper', :require => false
end

Expand Down Expand Up @@ -66,6 +77,17 @@ if puppet_gem_location != :gem || puppetversion < '3.5.0'
if Gem::Platform.local.os == 'mingw32'
explicitly_require_windows_gems = true
end

if puppet_gem_location == :gem
# If facterversion hasn't been specified and we are
# looking for a Puppet Gem version less than 3.5.0, we
# need to ensure we get a good Facter for specs.
gem "facter",">= 1.6.11","<= 1.7.5",:require => false unless facterversion
# If hieraversion hasn't been specified and we are
# looking for a Puppet Gem version less than 3.5.0, we
# need to ensure we get a good Hiera for specs.
gem "hiera",">= 1.0.0","<= 1.3.0",:require => false unless hieraversion
end
end

if explicitly_require_windows_gems
Expand All @@ -78,10 +100,6 @@ if explicitly_require_windows_gems
gem "win32-security", "~> 0.1.2", :require => false
gem "win32-service", "0.7.2", :require => false
gem "minitar", "0.5.4", :require => false
# If facterversion hasn't been specified and we are
# looking for a Puppet Gem version less than 3.5.0, we
# need to ensure we get a good Facter for Windows specs.
gem "facter",">= 1.6.11","<= 1.7.5",:require => false unless facterversion
else
gem "ffi", "~> 1.9.0", :require => false
gem "win32-eventlog", "~> 0.5", :require => false
Expand All @@ -108,8 +126,14 @@ if explicitly_require_windows_gems
gem "windows-pr", "1.2.3", :require => false
end

# Evaluate Gemfile.local if it exists
if File.exists? "#{__FILE__}.local"
eval(File.read("#{__FILE__}.local"), binding)
end

# Evaluate ~/.gemfile if it exists
if File.exists?(File.join(Dir.home, '.gemfile'))
eval(File.read(File.join(Dir.home, '.gemfile')), binding)
end

# vim:ft=ruby
7 changes: 4 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -180,13 +181,13 @@
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2013 Puppet Labs
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -198,4 +199,4 @@
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.
limitations under the License.
6 changes: 6 additions & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Maintenance

Maintainers:
- Puppet Windows Team `windows |at| puppet |dot| com`

Tickets: https://tickets.puppet.com/browse/MODULES. Make sure to set component to `powershell`.
16 changes: 16 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Puppet Module - puppetlabs-powershell

Copyright 2013 Josh Cooper, original author
Copyright 2013 - 2016 Puppet, 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.
53 changes: 28 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

##Overview

This module adds a new exec provider capable of executing PowerShell commands.
This module adds a new exec provider capable of executing PowerShell commands.

##Module Description

Expand All @@ -27,52 +27,55 @@ This module requires PowerShell to be installed and the `powershell.exe` to be a

###Beginning with powershell

The powershell module adapts the Puppet [exec](http://docs.puppetlabs.com/references/stable/type.html#exec) resource to run PowerShell commands. To get started, simply install the module and declare 'powershell' in `provider` with the applicable command.
The powershell module adapts the Puppet [exec](http://docs.puppet.com/references/stable/type.html#exec) resource to run PowerShell commands. To get started, simply install the module and declare 'powershell' in `provider` with the applicable command.

~~~
exec { 'RESOURCENAME':
command => '$(SOMECOMMAND)',
provider => powershell,
}
~~~ puppet
exec { 'RESOURCENAME':
command => '$(SOMECOMMAND)',
provider => powershell,
}
~~~

##Usage

When using `exec` resources with the `powershell` provider, the `command` parameter must be single-quoted to prevent Puppet from interpolating `$(..)`.
When using `exec` resources with the `powershell` provider, the `command` parameter must be single-quoted to prevent Puppet from interpolating `$(..)`.

For instance, if you wanted to rename the Guest account:

~~~
exec { 'rename-guest':
command => '$(Get-WMIObject Win32_UserAccount -Filter "Name=\'guest\'").Rename("new-guest")',
unless => 'if (Get-WmiObject Win32_UserAccount -Filter "Name=\'guest\'") { exit 1 }',
provider => powershell,
}
~~~ puppet
exec { 'rename-guest':
command => '$(Get-WMIObject Win32_UserAccount -Filter "Name=\'guest\'").Rename("new-guest")',
unless => 'if (Get-WmiObject Win32_UserAccount -Filter "Name=\'guest\'") { exit 1 }',
provider => powershell,
}
~~~

Note that the example uses the `unless` parameter to make the resource idempotent. The `command` is only executed if the Guest account does not exist, as indicated by `unless` returning 0.

**Note:** PowerShell variables (e.g. `$_`), must be escaped in Puppet manifests either using backslashes or single quotes.

Alternatively, you can put the PowerShell code for the `command`, `onlyif`, and `unless` parameters into separate templates and then invoke the template function in the resource.
Alternatively, you can put the PowerShell code for the `command`, `onlyif`, and `unless` parameters into separate files and then invoke the file function in the resource. Templates and the `template()` function could also be used here if the PowerShell scripts need to have access to variables from Puppet.

~~~
~~~ puppet
exec { 'rename-guest':
command => template('guest/rename-guest.ps1'),
onlyif => template('guest/guest-exists.ps1'),
command => file('guest/rename-guest.ps1'),
onlyif => file('guest/guest-exists.ps1'),
provider => powershell,
logoutput => true,
}
~~~

Each template is a PowerShell script.
Each file is a PowerShell script that should be in the module's `files/` folder.

~~~
For example, here is the script at: `guest/files/rename-guest.ps1`

~~~ powershell
$obj = $(Get-WMIObject Win32_UserAccount -Filter "Name='Guest'")
$obj.Rename("OtherGuest")
~~~

This has the added benefit of not requiring escaping '$' in the PowerShell code.
This has the added benefit of not requiring escaping '$' in the PowerShell code. Note that the files need to have DOS linefeeds or they will not work as expected. One tool for converting UNIX linefeeds to DOS linefeeds is [unix2dos](http://freecode.com/projects/dos2unix).


##Reference

Expand Down Expand Up @@ -101,13 +104,13 @@ Defines whether to log command output in addition to logging the exit code. If y
Runs the exec only if the command returns 0. Valid options: String. Default: Undefined.

#####`path`
Specifies the search path used for command execution. Valid options: String of the path, an array, or a semicolon-separated list. Default: Undefined.
Specifies the search path used for command execution. Valid options: String of the path, an array, or a semicolon-separated list. Default: Undefined.

#####`refresh`
Refreshes the command. Valid options: String. Default: Undefined.

#####`refreshonly`
Refreshes the command only when a dependent object is changed. Used with `subscribe` and `notify` [metaparameters](http://docs.puppetlabs.com/references/latest/metaparameter.html). Valid options: 'true', 'false'. Default: 'false'.
Refreshes the command only when a dependent object is changed. Used with `subscribe` and `notify` [metaparameters](http://docs.puppet.com/references/latest/metaparameter.html). Valid options: 'true', 'false'. Default: 'false'.

#####`returns`
Lists the expected return code(s). An error will be returned if the executed command returns something else. Valid options: An array of acceptable return codes or a single value. Default: 0.
Expand All @@ -117,7 +120,7 @@ Sets the maximum time in seconds that the command should take. Valid options: Nu

#####`tries`
Determines the number of times execution of the command should be attempted. Valid options: Number or a string representation of a number. Default: '1'.

#####`try_sleep`
Specifies the time to sleep in seconds between `tries`. Valid options: Number or a string representation of a number. Default: Undefined.

Expand All @@ -130,4 +133,4 @@ Runs the `exec`, unless the command returns 0. Valid options: String. Default: U

##Development

Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. For more information, see our [module contribution guide.](https://docs.puppetlabs.com/forge/contributing.html)
Puppet Inc modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. For more information, see our [module contribution guide.](https://docs.puppet.com/forge/contributing.html)
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 1.1.x.{build}
skip_commits:
message: /(^\(?doc\)?.*|.*[A|a]cceptance [T|t]est.*)/
message: /^\(?doc\)?.*/
clone_depth: 10
init:
- SET
Expand All @@ -24,14 +24,13 @@ matrix:
fast_finish: true
install:
- SET PATH=C:\Ruby%RUBY_VER%\bin;%PATH%
- gem install bundler --quiet --no-ri --no-rdoc
- bundle install --jobs 4 --retry 2 --without system_tests
- type Gemfile.lock
build: off
test_script:
- bundle exec puppet -V
- ruby -v
- bundle exec rspec spec/unit -fd -b
- bundle exec rspec spec/unit spec/integration -fd -b
notifications:
- provider: Email
to:
Expand Down
Loading