CmdLets/Install-LibraryApplication.ps1
|
Function Install-LibraryApplication { [CmdletBinding()] Param( [Parameter(Mandatory=$True,ValueFromPipeline=$True)] $Application, [Parameter(Mandatory=$True)] [System.IO.FileInfo]$Path ) Begin { } Process{ ForEach ($Item in $Application.Install) { Write-Progress -ID 0 -Activity "Installing Applications" -Status "Installing: $($Application.Name)" #This Replace is here while the Json contains both Relative paths and not, the goal is to have relative paths $Item.Path = $Item.Path.Replace("[SoftwarePath]",$Path).Replace("[Name]",$Application.Name).Replace("\\","") $Item.Arguments = $Item.Arguments.Replace("[SoftwarePath]",$Path).Replace("[Name]",$Application.Name).Replace("\\","") #The above line assumes relative and NON-UNC paths, so replace \\ with \ ForEach ($ScriptBlock in $Item.PreScriptBlocks) { Write-Verbose "Executing: $Scriptblock" Invoke-Command -ScriptBlock ([ScriptBlock]::Create($ScriptBlock)) -NoNewScope } If ($Item.Path){ $Files = Get-ChildItem $Item.Path -Recurse:$Item.Recurse } ForEach($File in $Files) { Write-Host $File.FullName If ($Item.Arguments) { $Process = Start-Process -FilePath $File.FullName -ArgumentList "$($Item.Arguments)" -PassThru } else { $Process = Start-Process -FilePath $File.Fullname -PassThru } Watch-Process -Process $Process Start-Sleep -Seconds 1 } ForEach ($ScriptBlock in $Item.PostScriptBlocks) { Write-Verbose "Executing: $Scriptblock" Invoke-Command -ScriptBlock ([ScriptBlock]::Create($ScriptBlock)) -NoNewScope } } } End{ Write-Progress -ID 0 -Activity "Installing Applications" -Completed } } |