If/Then Statement for Install


I’m trying to included the following in the Deploy-Application.ps1 script under the Installation space:
$driverVersion = gwmi win32_PnpSignedDriver | where{$_.Description -eq “Integrated Camera”} | Select DriverVersion

if(($driverVersion).DriverVersion -notmatch 10.1.19041.20146) {
Execute-Process -Path ‘dpinst.exe’ -Parameters ‘/f /s’
It wasn’t running the Execute-Process. But everything I had in the Post-Installation area (setting registry keys/values) Ran fine and I couldn’t find anything in the log. What would be the proper way to have this run?


You can do what you are trying to if the property DriverVersion is a string but you are matching with something that is not a string.

$test = 10.1.19041.20146
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $test.GetType()
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

If you can get by with a simple “if not” you can do as you are trying to but sometimes you want to compare if versions are greater than or less than. In the case of greater / less you can create a System.Version object to get accurate results.

if (([System.Version]::new($driverVersion.DriverVersion) -ne ([System.Version]::new('10.1.19041.20146'))) {

If you want to use -notmatch you need to encapsulate 10.1.19041.20146 with quotes to make powershell use it as a string.

if(($driverVersion).DriverVersion -notmatch '10.1.19041.20146') {

Thank you for that! And, is it correct to place it under the Installation portion of the App-Deploy.ps1 script with Execute-Process in my script block?

You can place it in w/e phase you like. Personally I try to keep stuff that needs to be done before the setup runs in pre-install, the installation itself during… install! ( :slight_smile: ) and shortcuts etc during post-install.

Thank you very much.