Public/Install-P1Demo.ps1

function Install-P1Demo {
    <#
    .Synopsis
    Install PlannerOne for an existing instance of Dynamics NAV.
 
    .Description
    Detect NAV version and instances, and configure a Plannerone tenant named Demo.
    #>

    [cmdletbinding()]
    param( 
    )    
    Process {
        Initialize-NAVVersion

        $P1Tenant = "Demo"
        $NAVInstances = Get-NAVServerInstance

        if ($NAVInstances.GetType().IsArray) {
            Write-Warning "Multi-instance not supported yet in this DEMO scenario!"
            Write-Warning "Run command Get-P1SampleScript and customize the script with your values."
            return
        } else {
            $NAVInstance = $NAVInstances
        } 

        # Technical account (must exist in $NAVInstance database)
        # Replace this value if the current user is not the technical account
        $UserDomain = $env:USERDOMAIN
        $UserLogin = $env:USERNAME
        $UserPassword = Read-Host -assecurestring "Please enter your password"        

        $features = Test-P1Prerequisites

        $missingFeatures = ($features | Where-Object InstallState -ne Installed)

        if ($missingFeatures.Count -eq 0) {
            $ERP = "NAV"
            $Version = $NavVersion
            # Install PlannerOne packages
            Install-P1Package -ERP $ERP -Version $Version

            # Create new tenant
            New-P1Tenant $P1Tenant -ERP $ERP

            # Configure adapter of tenant
            Set-P1Adapter -Tenant $P1Tenant -InstanceName $NAVInstance -ServiceDomain $UserDomain -ServiceLogin $UserLogin -ServicePassword $UserPassword -AutoPort

            # Get environments of tenant and save them in a variable
            $envList += Get-P1Environments -Tenant $P1Tenant -Product "Production" 
            $envList += Get-P1Environments -Tenant $P1Tenant -Product "Project" 

            # Initialize all environments in list
            Initialize-P1Environments -Tenant $P1Tenant -Environments $envList
            
        } else {
            $missingFeatures
        }
    }
}