Proper If elseif Statement

Oh I can so use your help here with a script I have been fighting with for a bit. I suspect it may be due to the manner I have the structure setup

The PS script is needed to run on both a Task Sequence (TS) and as a standard App Catalog install. I have it set as two groups of an If elseif. I have included only the area where it needs to do this work. Once I have the variable set the rest of the script is working.

This first section is checking if the script is running in a task sequence My understanding is if this is false it will skip all this and go to the next section below

If ($runningTaskSequence -eq $true){
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$strRegioncode = $TSEnv.Value(“OSDDomainName”)

If ($strRegioncode -eq '') { $InstPath = 'SetInstallPath' }
ElseIf ($strRegioncode -eq '') { $InstPath = 'SetInstallPath2' }
ElseIf ($strRegioncode -eq '') { $InstPath = 'SetInstallPath3' }


Then this section is run for all installs. If it is run in a TS it does not matter it would get the variable and do nothing with it. As I am writing this I see I may want to set If ($runningTaskSequence -eq $false

$strSappiDomain = (Get-WmiObject Win32_ComputerSystem).Domain
If ($strDomain -eq '') { $InstPath = 'SetInstallPath' }
ElseIf ($strDomain -eq '') { $InstPath = 'SetInstallPath2' }
ElseIf ($strDomain -eq '') { $InstPath = 'SetInstallPath3' }

Before any asks what the log is saying… that is another issue the logs are not being created.

This script runs fine if I run it via the Application Catalog and a normal deployment. Including the logs

Your help is absolutely appreciated on this very frustrating issue.


Seems to me that you already had all the pieces just had to combine it.

If ($runningTaskSequence -eq $true){
    $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
    $strRegioncode = $TSEnv.Value(“OSDDomainName”)
} Else {
    $strRegioncode = (Get-WmiObject Win32_ComputerSystem).Domain

switch ($strRegioncode) {
    '' {$InstPath = 'SetInstallPath'}
    '' {$InstPath = 'SetInstallPath2'}
    '' {$InstPath = 'SetInstallPath3'}
    default {Write-Log "Something went wrong"}