I am trying to install topshelf using powershell, but I am really trying to get powershell to run the installer.
Function EnsureTopshelfService([string]$serviceName, [string]$servicePath){
$service = get-service $serviceName -ErrorAction SilentlyContinue
if ($service –ne $null){
"$serviceName is already installed on this server";
}
else{
Write-Host "Installing $serviceName...";
& "`"$servicepath`" install --sudo"
}
}
When I run this command, I get the following
Installing a test ... and: The term "c: \ A Test \ Test.exe" install --sudo is not recognized as the name of a cmdlet, function, script file, or a running program. Check the spelling of the name, or if the path was included, check the path and try again. In C: \ Users \ luke.mcgregor \ Documents \ Test.ps1: 11 char: 11 + and " "$servicepath" install --sudo "+ ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ + CategoryInfo: ObjectNotFound: ("c: \ A Test \ Test.exe" set --sudo: String) [], CommandNotFoundException + FullyQualifiedErrorId: CommandNotFoundException
Running "c:\A Test\Test.exe" install --sudoon the command line works fine, so the problem is how im refers to an existing program. Does anyone know where I made a mistake here? I'm new to PowerShell, so I guess this is a pretty simple thing.
EDIT:
Function EnsureTopshelfService([string]$serviceName, [string]$servicePath){
$service = get-service $serviceName -ErrorAction SilentlyContinue
if ($service –ne $null){
"$serviceName is already installed on this server";
}
else{
Write-Host "Installing $serviceName...";
& "$servicepath" install --sudo
}
}