Public/New-P1ServerInstance.ps1

function New-P1ServerInstance {
    <#
    .Synopsis
    Install a new PlannerOne service.
 
    .Description
    Install a new PlannerOne service with the given parameters.
 
    .Parameter Tenant
    The tenant name of this service.
 
    .Parameter Domain
    The domain of the user that will run the service.
     
    .Parameter Login
    The login of the user that will run the service.
 
    .Parameter Password
    The password of the user that will run the service.
 
    .Example
    # Install a PlannerOne service for the tenant Prod.
    New-P1ServerInstance -Tenant Prod -Login PlanAdm -Password MyPassword
    #>

    [cmdletbinding()]
    param( 
        [string] $Tenant,
        [string] $Domain,
        [string] $Login,
        [string] $Password
    )
    Process
    {
        $serviceName = Get-ServiceNameFromTenant $Tenant
        $displayName = Get-ServiceDisplayNameFromTenant $Tenant
        $servicePath = Get-ServicePath
        
        $srvBinPath = Get-PackageFolder($P1SrvPackage)
        $srvBinFolder = "AppServer"

        #Test if service already exists
        if (Test-ServiceExists($serviceName)) {
            Write-Warning "Service $serviceName already exists!"
        } else {
            # Create folder for the service
            if (!(Test-Path $servicePath)) {
                mkdir $servicePath
            }
            
            # Link folder to repository
            $serverPath = Get-ServerPathFromTenant $Tenant
            New-Symlink $serverPath "$srvBinPath\$srvBinFolder"
            
            if ($Domain -eq "") {
                $Domain = $Env:COMPUTERNAME
            }
            
            #$securedPassword = ConvertTo-SecureString $Password -AsPlainText -Force
            #$serviceCredential = New-Object System.Management.Automation.PSCredential "$Domain\$Login" ,$securedPassword

            Write-Output "Creating new PlannerOne service for Tenant $Tenant"
            New-Service -Name $serviceName -BinaryPathName "$servicePath\$Tenant\$P1SrvExe" -displayName $displayName 
            # -Credential $serviceCredential
            Start-Service -Name $serviceName
        }
        
    }
}