Hi,
I’ve written this script that looks at a text file for certain fields then adds an App-v application into SCCM.
I’m pretty pleased but believe i can only use “try…catch” once, so how can i put in some error catching ?
#Set Application details to add to SCCM from text template
$DefaultAppPath = "\theaa.local\dfsdata\sccm\software"
$Content = get-content “\aa-cm002v\e$\scripts\AppV_Template.txt”
$App_DT_Name = $Content[3]
$App_Name = $Content[5]
$App_Source_Location = $Content[7]
$OptRef =
$Publisher = $Content[9]
$SoftVer = $Content[11]
$Folder = $Content[13]
#Full location path
$LocationFull = “$DefaultAppPath”+“$App_Source_Location”
#Set Module and CMsite directory
$ModulePath = “C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin”
$SetDrive = “set-location AAC:”
#Import module
Import-Module $ModulePath\ConfigurationManager.psd1
#Set directory
Invoke-expression $SetDrive
#Create new application. “#” if the below command is required.
Try {
New-CMApplication -Name $App_Name -AutoInstall $true -Publisher $Publisher -SoftwareVersion $SoftVer
Write-Output “Application Created Successfully”
exit 0 }
Catch {
Write-Output “Failed to create Application”
Exit 1001 }
#Create New Application deployment file
Try {
Add-CMDeploymentType -ApplicationName $App_Name -DeploymentTypeName $App_DT_Name -AppV5xInstaller -ForceForUnknownPublisher $true -InstallationFileLocation $LocationFull
Write-Output “Application Deployment file Created”
exit 0 }
Catch {
Write-Output “Failed to create Application Deployment file”
Exit 1001 }
#Move Application to folder
Try {
$GetApp = Get-CMApplication -name $App_Name
Move-CMObject -FolderPath “.\Application\Publisher$Folder” -InputObject $GetApp
Write-Output “Application moved to $folder folder”
exit 0 }
Catch {
Write-Output “Failed to move Application to Folder”
Exit 1001 }