Reputation: 15
I am working on an automation for installing software. The step I am currently working on is either executing a .msi file, or unzipping and moving a directory to the appropriate location for deployment. I am trying to utilize an IF statement to accomplish this, however, if my IF or ElseIF arguments are true, it still appears to pass through to the "Else" statement. My example is as follows:
$pattern2 = "abc"
$pattern3 = "Dot NET ABC"
$pattern4 = "ABC Serial Example"
$path2 = "C:Users\$env:UserName\Downloads\"
$ABSystem1 = Get-ChildItem -path $path2 | Where-Object {$_.Name -Match $pattern2}
$ABSystem2 = Get-ChildItem -path $path2 | Where-Object {$_.Name -Match $pattern3}
$ABSystem3 = Get-ChildItem -path $path2 | Where-Object {$_.Name -Match $pattern4}
$Destination2 = "C:Test\test-systems\$ClientName\ab\$ClientName\"
$InstallAB = {if ($ABSyetem1 -Match $pattern2 ) {
$ABName1 = $ABsystem1.Name
Expand-Archive -LiteralPath "C:\Users\$env:UserName\Downloads\$AbName1" -DestinationPath $Destination2
}
elseif ($ABSyetem2 -Match $pattern3) {
$ABName2 = $ABSystem2.Name
Start-Process "C:\users\$env:UserName\downloads\$ABName2"
}
else {
$ABName3 = $ABSystem3.Name
Start-Process "C:\users\$env:UserName\downloads\$ABName3"
}}
Basically an individual who would use this is going to download one of three versions. Based on what was downloaded, it will match the name and either execute the associated .msi, or expand the zip archive for deployment.
Am I passing in my IF arguments wrong? Can I use "-Match" "-Like", etc. when passing in a variable?
Upvotes: 0
Views: 193
Reputation: 27423
It would be if ($ABSystem1.name -match $pattern2)
etc. And you mispelled "system".
Upvotes: 1