Public/Get-P1SampleScripts.ps1

function Get-P1SampleScripts {
    <#
    .Synopsis
    Get sample scripts from PlannerOne Web Site.
 
    .Description
    The sample scripts could be adapted and customized to your need. It should work as-is if you're using Demo envrionment.
 
    .Example
    The ERP associated to sample scripts (NAV or SAGE).
 
    .Example
    # Get the sample scripts.
    Get-P1SampleScripts
    #>

    [cmdletbinding()]
    param(
        [string] $ERP
    )
    Process
    {
        if ($ERP -eq "") {
            $ERP = "NAV"
        }

        if ($ERP -ne "NAV" -and $ERP -ne "SAGE") {
            Write-Warning "Invalid ERP name. Please enter a valid value: NAV, SAGE"
            return
        }

        $DocumentsFolderPath = [Environment]::GetFolderPath("mydocuments")
        $LocalSamplesFolder = "$DocumentsFolderPath\P1Samples"
        if (!(Test-Path $LocalSamplesFolder)) {
            New-Item -Path "$LocalSamplesFolder" -ItemType Directory | Out-Null
            Write-Verbose "Folder $LocalSamplesFolder has been created."
        }

        $url = $SamplesURL.Replace("[ERP]", $ERP)
        Write-Verbose "Getting file list from URL $url/list.php."
        $FileList = (Invoke-WebRequest -Uri "$url/list.php").Content | ConvertFrom-Json

        $FileCount = $FileList.Count
        Write-Verbose "File list contains $FileCount files(s)."
        foreach ($File in $FileList) {
            Write-Verbose "Downloading file $url/$File"
            Invoke-WebRequest -Uri "$url/$File" -OutFile "$LocalSamplesFolder\$File" -Headers @{"Cache-Control"="no-cache";"User-Agent"="Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"} 
        }
        
        Write-Output "$FileCount sample scripts has been copied to folder $LocalSamplesFolder."
        Write-Output "Run ise to edit, customize and run the script the most adapted to your scenario."
    }
}