I'm writing a service installer script in Powershell where the service requires a complicated quoted command line.
So I tried to simplify it and broke each option down to individual variables, however when creating the final command line string the strings don't escape their quotes. Thus the command line doesn't work.
I'd like to keep all the options separate so that other admins can configure and install the service without needing to worry about escaping quotes.
I'm thinking I need to perform a search and replace or use a shell specific safe/escape string command to operate on the individual strings first.
I don't know how the command line of a service is parsed, so not sure which shell escape method to use.
I've done a search on quotes in strings but they never seem to deal with nesting of strings with quotes inside strings with quotes.
This is my install script and I do have control over the applicationservice, so if you know of a better method to get arguments into a service that would also be appreciated.
$installpath = (get-location)
$name="landingZone"
$displayName="LandingZone Starter"
$description="Sony CI automated download client"
$sessionuser="Engineering"
$processname="explorer"
$logname="Landing Zone"
$programpath="C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe"
$programarguments='"C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe -jar C:\Program Files (x86)\Sony CI\Sony-Ci-LZ-1.4.22\Sony-Ci-LZ-1.4.22.jar"'
$WorkDirectory="C:\Program Files (x86)\Sony CI\Sony-Ci-LZ-1.4.22"
$Visible=1
$TerminateTimeout=1000
# Arg! help me!
$binpath = $installpath.toString() + "\applicationservice.exe ""SessionUser=$sessionuser"" ""ProcessName=$processname"" ""LogName=$logname"" ""ProgramPath=$programpath"" ""ProgramArguments=$programarguments"" ""WorkDirectory=$workdirectory"" Visible=$visible TerminateTimeout=$terminatetimeout"
New-Service -Name $name -BinaryPathName $binPath -DisplayName $displayname -Description $description -StartupType Manual
Thanks