5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
##2015-05-24 - Supported Release 2.0.1
###Bug Fixes

- Updated the powershell manager in this module in order to not conflict with the Powershell Manager in the Puppet DSC module

##2015-05-17 - Supported Release 2.0.0
###Summary

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/exec/powershell.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'puppet/provider/exec'
require_relative '../../../puppet_x/puppetlabs/powershell_manager'
require_relative '../../../puppet_x/puppetlabs/powershell/powershell_manager'

Puppet::Type.type(:exec).provide :powershell, :parent => Puppet::Provider::Exec do
confine :operatingsystem => :windows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def exit
end

def template_path
File.expand_path('../../templates', __FILE__)
File.expand_path('../../../templates', __FILE__)
end

def make_ps_code(powershell_code, output_ready_event_name, timeout_ms = 300 * 1000)
Expand Down
5 changes: 3 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-powershell",
"version": "2.0.0",
"version": "2.0.1",
"author": "Puppet Inc",
"summary": "Adds a new exec provider for executing PowerShell commands.",
"license": "Apache-2.0",
Expand All @@ -16,7 +16,8 @@
"Server 2012",
"Server 2012 R2",
"7",
"8"
"8",
"10"
]
}
],
Expand Down
25 changes: 25 additions & 0 deletions spec/acceptance/exec_powershell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@

end

describe 'should handle a try/catch successfully' do

powershell_cmd = <<-CMD
try{
$foo = ls
$count = $foo.count
$count
}catch{
Write-Error "foo"
}
CMD

p1 = <<-MANIFEST
exec{'TestPowershell':
command => '#{powershell_cmd}',
provider => powershell,
}
MANIFEST

it 'should not error' do
apply_manifest(p1, :expect_changes => true, :future_parser => FUTURE_PARSER)
end

end

describe 'should run commands that exit session' do

exit_pp = <<-MANIFEST
Expand Down
18 changes: 17 additions & 1 deletion spec/integration/puppet_x/puppetlabs/powershell_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'
require 'puppet/type'
require 'puppet_x/puppetlabs/powershell_manager'
require 'puppet_x/puppetlabs/powershell/powershell_manager'

module PuppetX
module PowerShell
Expand Down Expand Up @@ -89,6 +89,22 @@ class PowerShellManager; end
expect(result[:exitcode]).to eq(0)
end

it "should execute code with a try/catch" do
result = manager.execute(<<-CODE
try{
$foo = ls
$count = $foo.count
$count
}catch{
Write-Error "foo"
}
CODE
)

expect(result[:stdout]).not_to eq(nil)
expect(result[:exitcode]).to eq(0)
end

it "should reuse the same PowerShell process for multiple calls" do
first_pid = manager.execute('[Diagnostics.Process]::GetCurrentProcess().Id')[:stdout]
second_pid = manager.execute('[Diagnostics.Process]::GetCurrentProcess().Id')[:stdout]
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/provider/exec/powershell_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/util'
require 'puppet_x/puppetlabs/powershell_manager'
require 'puppet_x/puppetlabs/powershell/powershell_manager'

describe Puppet::Type.type(:exec).provider(:powershell) do

Expand Down