You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-22Lines changed: 25 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@
14
14
15
15
##Overview
16
16
17
-
This module adds a new exec provider capable of executing PowerShell commands.
17
+
This module adds a new exec provider capable of executing PowerShell commands.
18
18
19
19
##Module Description
20
20
@@ -29,50 +29,53 @@ This module requires PowerShell to be installed and the `powershell.exe` to be a
29
29
30
30
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.
31
31
32
-
~~~
33
-
exec { 'RESOURCENAME':
34
-
command => '$(SOMECOMMAND)',
35
-
provider => powershell,
36
-
}
32
+
~~~puppet
33
+
exec { 'RESOURCENAME':
34
+
command => '$(SOMECOMMAND)',
35
+
provider => powershell,
36
+
}
37
37
~~~
38
38
39
39
##Usage
40
40
41
-
When using `exec` resources with the `powershell` provider, the `command` parameter must be single-quoted to prevent Puppet from interpolating `$(..)`.
41
+
When using `exec` resources with the `powershell` provider, the `command` parameter must be single-quoted to prevent Puppet from interpolating `$(..)`.
42
42
43
43
For instance, if you wanted to rename the Guest account:
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.
54
54
55
55
**Note:** PowerShell variables (e.g. `$_`), must be escaped in Puppet manifests either using backslashes or single quotes.
56
56
57
-
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.
57
+
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.
58
58
59
-
~~~
59
+
~~~puppet
60
60
exec { 'rename-guest':
61
-
command => template('guest/rename-guest.ps1'),
62
-
onlyif => template('guest/guest-exists.ps1'),
61
+
command => file('guest/rename-guest.ps1'),
62
+
onlyif => file('guest/guest-exists.ps1'),
63
63
provider => powershell,
64
64
logoutput => true,
65
65
}
66
66
~~~
67
67
68
-
Each template is a PowerShell script.
68
+
Each file is a PowerShell script that should be in the module's `files/` folder.
69
69
70
-
~~~
70
+
For example, here is the script at: `guest/files/rename-guest.ps1`
This has the added benefit of not requiring escaping '$' in the PowerShell code.
77
+
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).
78
+
76
79
77
80
##Reference
78
81
@@ -101,7 +104,7 @@ Defines whether to log command output in addition to logging the exit code. If y
101
104
Runs the exec only if the command returns 0. Valid options: String. Default: Undefined.
102
105
103
106
#####`path`
104
-
Specifies the search path used for command execution. Valid options: String of the path, an array, or a semicolon-separated list. Default: Undefined.
107
+
Specifies the search path used for command execution. Valid options: String of the path, an array, or a semicolon-separated list. Default: Undefined.
105
108
106
109
#####`refresh`
107
110
Refreshes the command. Valid options: String. Default: Undefined.
@@ -117,7 +120,7 @@ Sets the maximum time in seconds that the command should take. Valid options: Nu
117
120
118
121
#####`tries`
119
122
Determines the number of times execution of the command should be attempted. Valid options: Number or a string representation of a number. Default: '1'.
120
-
123
+
121
124
#####`try_sleep`
122
125
Specifies the time to sleep in seconds between `tries`. Valid options: Number or a string representation of a number. Default: Undefined.
0 commit comments