CmdLets/Install-Applications.ps1

Function Install-Applications 
 {

    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True)]
            $Applications
        )

    ForEach ($Application in $Applications) {
        $i++; Write-Progress -ID 0 -Activity "Installing Applications" -Status "Installing: $($Application.Name)" -PercentComplete (($i/$Applications.Count)*100);
        Write-Host "Installing: $($Application.Name)"
        #This Replace is here while the Json contains both Relative paths and not, the goal is to have relative paths
        If ($Application.Path) { $Application.Path = $Application.Path.Replace("[SoftwarePath]",$SoftwarePath).Replace("[Name]",$Application.Name).Replace("\\","\") }
        If ($Application.Arguments) {$Application.Arguments = $Application.Arguments.Replace("[SoftwarePath]",$SoftwarePath).Replace("[Name]",$Application.Name).Replace("\\","\")}
        #The above line assumes relative and NON-UNC paths, so replace \\ with \

        ForEach ($ScriptBlock in $Application.PreScriptBlocks) { 
            Write-Host $ScriptBlock
            Invoke-Command -ScriptBlock ([ScriptBlock]::Create($ScriptBlock)) -NoNewScope
        }

        If ($Application.Path) {
            If ($Application.NonRecurse) {
                $Files = Get-ChildItem $Application.Path
            } else {
                $Files = Get-ChildItem $Application.Path -Recurse     
            }
            
            ForEach($File in $Files) {
                Write-Host $File.FullName
                If ($Application.Arguments) {
                    $Process = Start-Process -FilePath $File.FullName -ArgumentList "$($Application.Arguments)" -PassThru
                } else {
                    $Process = Start-Process -FilePath $File.Fullname -PassThru
                }

                Watch-Process -Process $Process
                Start-Sleep -Seconds 1
            }
        }
        ForEach ($ScriptBlock in $Application.PostScriptBlocks) { 
            Write-Host $ScriptBlock
            Invoke-Command -ScriptBlock ([ScriptBlock]::Create($ScriptBlock)) -NoNewScope
        }
    }
    Write-Progress -ID 0 -Activity "Installing Applications" -Completed

}