Install topshelf service using powershell

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...";

        #the problem is here
        & "`"$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
    }
}
+5
2

, . -

& "`"$servicepath`" install --sudo"

3 -

& $servicepath install --sudo

- PowerShell. , , CMD.exe. , .

.

+5

(weird/crazy/take-your-pick), .

, EXE, topshelf C:\Services\ItJustWorks\ItJustWorks.exe, powershell:

PS C:\Services\ItJustWorks> .\ItJustWorks.exe install -servicename:"ItJustWorks"
+1

All Articles