Question: How do I get a forward slash ("/") to be passed from a Puppet manifest on a Linux server with Puppet Master to a Windows Server with Puppet Agent?
Answer # 1 (for creating Scheduled Tasks with Puppet manifests): For a Scheduled Task, the forward slash may be crucial. A forward slash (that Puppet between Linux and Windows will automatically substitute for a back slash) with a shutdown.exe server is the only way for a reboot to work properly with a Scheduled Task. In a Puppet manifest (.pp file), declare a Scheduled_Task resource (where the link used to be here https://docs.puppet.com/puppet/latest/reference/types/scheduled_task.html). This is a built-in resource type for Puppet.
While this solution does not give you a forward slash in the end result, it will give you a solution by having an "argument." The "arguments =>" property will allow you to place an "\r" in the "Add arguments" field in the "Edit Action" window found by clicking "Edit" in the "Actions" tab of the Scheduled Task. When you manually create a Scheduled Task, the "...shutdown.exe /r ..." can all appear the "Program/script" field together. A backslash before the "r" in the "Program/script" field will not allow you to reboot the server. But a backslash before the "r" in the "Add arguments" field will allow you to reboot the server.
Answer #2 (for passing a "/" to in a PowerShell command): Use the [char]47 command in PowerShell to get a variable with a forward slash "/". PowerShell commands can be compound with semi colons ";" separating distinct lines. Therefore something like this will work (with assigning [char]47 to a variable and concatenating strings to ultimately call everything with the invoke-expression command:
command => '$fslash = [char]47; $construct = "schtasks " + $fslash + "create " + $fslash + "sc monthly " + $fslash + "tn continualIntegration " + $fslash + "tr c:\windows\system32\fun.exe " + $fslash + "sd 09/08/2016"; invoke-expression $construct'
Answer #3 (transfer a file via a manifest): A manifest can have a resource definition like this:
file { "c:\temp\special.ps1":
source => puppet:/// /special.ps1
}
# special.ps1 can have forward slashes in it.
# This file would have to be in /etc/puppetlabs/code/environments/development/modules/foobar/files/
# Note that "files" (the subdirectory holding the file) is omitted from the source declaration in the manifest.
This method could involve an exec resource definition with a command call. This way you could run a PowerShell command with a forward slash. Other files (with forward slashes) besides those with .ps1 extensions could similarly be transferred to a Windows server.
Answer #4 (use the provider key word): A manifest with a resource definition of command can have a provider declaration too. A manifest written like this will actually work:
command => '$construct = "schtasks /create /sc monthly /tn continualIntegration /tr c:\windows\system32\fun.exe /sd 09/08/2016"; invoke-expression $construct',
provider => 'powershell',