powershell - If/ elseif giving wrong output -


i having issues script returning correct output:

$maximiser = get-childitem -path c:\windows\system32\maximiser.tsp | select name $id6 = get-itemproperty -path 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' | select providerid6  $id5 = get-itemproperty -path 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' | select providerid5 $id4 = get-itemproperty -path 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' | select providerid4 $id3 = get-itemproperty -path 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' | select providerid3 $id2 = get-itemproperty -path 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' | select providerid2 $id1 = get-itemproperty -path 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' | select providerid1 $id = get-itemproperty -path 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' | select providerid $nomax = "maximiser no installed" $noid = "providerid not configured" write-host 'this computer called' $env:computername  if ($maximiser = $maximiser) { write-host "maxmiser installed"} else {write-host "$nomax"} if ($id6 = $id6 ) { write-host "provider id configured"} elseif ($id5 = $id5) { write-host "provider id configured"} elseif ($id4 = $id4) { write-host "provider id configured"} elseif ($id3 = $id3) { write-host "provider id configured"} elseif ($id2 = $id2) { write-host "provider id configured"} elseif ($id1 = $id1) { write-host "provider id configured"} elseif ($id = $id) { write-host "provider id configured"}  else {write-host "provider id not configured"}  

for reason - keep on getting "maximiser installed" , "provider id configured" though not. missing major in this?

edit if have found answer (because have multiple providerid's) using :

if ($id -like (get-itemproperty -path 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' | select-object -expandproperty providerid )) { write-host "provider id configured"} else {write-host "provider id not configured"}  

this seems work!

something ...

if ($id.providerid -ne $null) {      # action if  providerid in 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' doesnt has value.  } 

... in current state should work.

also not need fetch same data 7 times different variables ... there.

$id = get-itemproperty -path 'hklm:\software\microsoft\windows\currentversion\telephony\providers\' 

... result in ...

$id.providerid $id.providerid1 .. $id.providerid6 

... having data need comparison.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -