none
Imbrication IF et SWITCH dans détection Make-Model sous tâche MDT RRS feed

  • Question

  • Bonjour je suis relativement nouveau au powershell et je me suis essayé sur un ps1 qui permet la mise à jour du bios d'un PC lors de l'utilisation avec MDT via une task Sequence.

    Tout me semblait correct (après avoir testé sur différents postes) jusqu'au jour ou j'ai ajouté le segment du IF pour le Optiplex 990. 

    #IF Optiplex 990 START

    Lorsque l'appareil arrive à cette tâche même si le 

    $Make = $TSEnv.Value("Make")

    est bien déterminé

    Property Make is now = Dell Inc.]LOG]type="1" thread="" file="ZTIGather">
    Property Model is now = OptiPlex 990

    le processus passe toujours par la section du Optiplex 790 et une erreur à l'évidence de fichier introuvable s'affiche...

    #Load MDT Task Sequence Environment and Logs
    $TSenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
    $logPath = $tsenv.Value("LogPath") 
    #$date = get-date -format g
    
    #Collect data
    Write-Output "Collecting Data" >> $logFile
    $ScriptRoot = (Get-location).Path
    $Make = $TSEnv.Value("Make")
    $Model = $TSenv.Value("Model")
    $CompBiosVersion = (Get-WmiObject WIN32_BIOS).SMBIOSBIOSVersion
    ###
    ##$make = (Get-WmiObject Win32_Computersystem).manufacturer
    ##$model = (Get-WmiObject Win32_Computersystem).model
    ###
    #Info des Versions de BIOS
    #790
    $B79021 = "A21"
    $B79020 = "A20"
    $B79010 = "A10"
    $B79009 = "A09"
    $B79005 = "A05"
    #990
    $B99023 = "A23"
    $B99022 = "A22"
    $B99010 = "A10"
    $B99009 = "A09"
    $B99005 = "A05"
    #7010
    $B701028 = "A28"
    #5570
    $B55701186 = "1.18.6"
    #7050
    $B7050183 = "1.8.3"
    $param1 = "/noreboot /s"
    
    #Start the logging
    $logFile = "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\BIOS_Update.log"
    Write-Output "Logging to $logFile" > $logFile
    
    #Make Selection from Manufacturer--------------------------------------------------------------------------------------------------------------------MAKE
    Switch ($Make)
    {
      "HP"  {
        #Clear-Host
        write-output "HP"
        break
      }
    #Switch Dell system START--------------------------------------------------------------------------------------------------------------------------START
      "Dell Inc."{
        #Clear-Host
        write-output "$Make"
        write-output "$Model"
    #IF Optiplex 790 START-------------------------------------------------------------------------------------------------------------------------------START              
                    if($Model -ieq $TSenv.Value("Model") -ieq "Optiplex 790"){
                        if($CompBiosVersion.replace(' ' , '') -eq $B79021.replace(' ' , '')) {
                            Write-Output "BIOS is up to date." >> $logFile
                            Stop-Transcript
                            Exit
                            }
                        elseif ($CompBiosVersion.replace(' ' , '') -ge $B79010.replace(' ' , '') -and ($CompBiosVersion.replace(' ' , '') -le $B79020.replace(' ' , ''))) {
                                Write-Output "Updating BIOS $CompBiosVersion to $B79021." >> $logFile
    	                        #Write-Output "Installer path $Model - $Installer21" >> $logFile
    	                        Start-Process -FilePath "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\O790-A21.exe" -ArgumentList "$param1" -Wait
                                $tsenv.Value("NeedReboot") = "YES"
                                Write-Output "Update has been completed successfully." >> $logFile
                            Exit
                            }
                        elseif ($CompBiosVersion.replace(' ' , '') -ge $B79005.replace(' ' , '') -and ($CompBiosVersion.replace(' ' , '') -le $B79009.replace(' ' , ''))) {
                                Write-Output "Updating BIOS $CompBiosVersion to $B79010." >> $logFile
    	                        #Write-Output "Installer path $Model - $Installer10" >> $logFile
    	                        Start-Process -FilePath "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\O790-A10.exe" -ArgumentList "$param1" -wait
                                $tsenv.Value("NeedReboot") = "YES"
                                Write-Output "Update has been completed successfully." >> $logFile
                            Exit
                            }
                        else { Write-Output "Updating BIOS $CompBiosVersion to $B79005." >> $logFile
                                Start-Process -FilePath "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\O790-A05.exe" -ArgumentList "$param1" -wait
                                $tsenv.Value("NeedReboot") = "YES"
                                Write-Output "Update has been completed successfully." >> $logFile
                            Exit
    	                    }
                                                                        }
    #IF Optiplex 790 STOP-----------------------------------------------------------------------------------------------------------------------------STOP
    
    #IF Optiplex 990 START-------------------------------------------------------------------------------------------------------------------------------START              
                    if($Model -ieq $TSenv.Value("Model") -ieq "Optiplex 990"){
                        if($CompBiosVersion.replace(' ' , '') -eq $B99023.replace(' ' , '')) {
                            Write-Output "BIOS is up to date." >> $logFile
                            Stop-Transcript
                            Exit
                            }
                        elseif ($CompBiosVersion.replace(' ' , '') -ge $B99010.replace(' ' , '') -and ($CompBiosVersion.replace(' ' , '') -le $B99022.replace(' ' , ''))) {
                                Write-Output "Updating BIOS $CompBiosVersion to $B99023." >> $logFile
    	                        #Write-Output "Installer path $Model - $Installer21" >> $logFile
    	                        Start-Process -FilePath "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\O990-A23.exe" -ArgumentList "$param1" -Wait
                                $tsenv.Value("NeedReboot") = "YES"
                                Write-Output "Update has been completed successfully." >> $logFile
                            Exit
                            }
                        elseif ($CompBiosVersion.replace(' ' , '') -ge $B99005.replace(' ' , '') -and ($CompBiosVersion.replace(' ' , '') -le $B99009.replace(' ' , ''))) {
                                Write-Output "Updating BIOS $CompBiosVersion to $B99010." >> $logFile
    	                        #Write-Output "Installer path $Model - $Installer10" >> $logFile
    	                        Start-Process -FilePath "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\O990-A10.exe" -ArgumentList "$param1" -wait
                                $tsenv.Value("NeedReboot") = "YES"
                                Write-Output "Update has been completed successfully." >> $logFile
                            Exit
                            }
                        else { Write-Output "Updating BIOS $CompBiosVersion to $B99005." >> $logFile
                                Start-Process -FilePath "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\O990-A05.exe" -ArgumentList "$param1" -wait
                                $tsenv.Value("NeedReboot") = "YES"
                                Write-Output "Update has been completed successfully." >> $logFile
                            Exit
    	                    }
                                                                        }
    #IF Optiplex 990 STOP-----------------------------------------------------------------------------------------------------------------------------STOP
    
    
    #IF Optiplex 7010 START---------------------------------------------------------------------------------------------------------------------------START
                    if($Model -ieq $TSenv.Value("Model") -ieq "Optiplex 7010"){
                        if($CompBiosVersion.replace(' ' , '') -eq $B701028.replace(' ' , '')) {
                            Write-Output "BIOS is up to date." >> $logFile
                            Stop-Transcript
                            Exit
                            }
                        else { Write-Output "Updating BIOS $CompBiosVersion to $B7010028." >> $logFile
                                Start-Process -FilePath "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\O7010A28.exe" -ArgumentList "$param1" -Wait
                                $tsenv.Value("NeedReboot") = "YES"
                                Write-Output "Update has been completed successfully." >> $logFile
                            Exit
    	                    }
                                                                        }
    #IF Optiplex 7010 STOP----------------------------------------------------------------------------------------------------------------------------STOP
    #IF Latitude E5570 START---------------------------------------------------------------------------------------------------------------------------START
                    if($Model -ieq $TSenv.Value("Model") -ieq "Latitude 5570"){
                        if($CompBiosVersion.replace(' ' , '') -eq $B55701186.replace(' ' , '')) {
                            Write-Output "BIOS is up to date." >> $logFile
                            Stop-Transcript
                            Exit
                            }
                        else { Write-Output "Updating BIOS $CompBiosVersion to $B55701186." >> $logFile
                                Start-Process -FilePath "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\Latitude_E5x70_Precision_3510_1.18.6.exe" -ArgumentList "$param1" -Wait
                                $tsenv.Value("NeedReboot") = "YES"
                                Write-Output "Update has been completed successfully." >> $logFile
                            Exit
    	                    }
                                                                        }
    #IF Latitude 5570 STOP----------------------------------------------------------------------------------------------------------------------------STOP
    #IF Optiplex 7050 START---------------------------------------------------------------------------------------------------------------------------START
                    if($Model -ieq $TSenv.Value("Model") -ieq "Optiplex 7050"){
                        if($CompBiosVersion.replace(' ' , '') -eq $B7050183.replace(' ' , '')) {
                            Write-Output "BIOS is up to date." >> $logFile
                            Stop-Transcript
                            Exit
                            }
                        else { Write-Output "Updating BIOS $CompBiosVersion to $B7050183." >> $logFile
                                Start-Process -FilePath "\\AdresseIP\DeploymentShare$\Scripts\Custom\Bios\$Model\OptiPlex_7050_1.8.3.exe" -ArgumentList "$param1" -Wait
                                $tsenv.Value("NeedReboot") = "YES"
                                Write-Output "Update has been completed successfully." >> $logFile
                            Exit
    	                    }
                                                                        }
    #IF Optiplex 7050 STOP----------------------------------------------------------------------------------------------------------------------------STOP
    
                   break
                   }
    #Switch Dell system STOP--------------------------------------------------------------------------------------------------------------------------STOP
      "Lenovo"{
        #Clear-Host
        write-output "Lenovo"
        break
      }
      "Toshiba"{
        #Clear-Host
        write-output "Toshiba"
        break
      }
        default {Write-Output "Impossible de determiner votre systeme"; break}
    }
    #Make Selection from Manufacturer-----------------------------------------------------------------------------------------------------------------MAKE

    J'ai certainement une erreur dans le IF ou est ce l'imbrication dans le SWITCH ou la combinaison?

    Si quelqu'un pouvait m'éclairer et m'aider à mettre de l'ordre et trouver la raison de l'erreur j'en serais ravis

    Merci

    jeudi 3 mai 2018 01:28

Réponses

  • Bonjour,

    Je pense qu'il y a un problème dans vos if avec une partie inutile.

    if($Model -ieq $TSenv.Value("Model") -ieq "Optiplex 790")

    Le but c'est pas plutôt :

    if($Model -ieq "Optiplex 790")


    Merci de marquer comme reponses les interventions qui vous ont ete utile.


    jeudi 3 mai 2018 08:24

Toutes les réponses

  • Bonjour,

    Je pense qu'il y a un problème dans vos if avec une partie inutile.

    if($Model -ieq $TSenv.Value("Model") -ieq "Optiplex 790")

    Le but c'est pas plutôt :

    if($Model -ieq "Optiplex 790")


    Merci de marquer comme reponses les interventions qui vous ont ete utile.


    jeudi 3 mai 2018 08:24
  • Merci bien c'est effectivement l'élément qui était problématique :)

    J'avais fais quelques tests avec la variable $Model en local et bien que commentée j'avais oublié de la retirer dans le IF....d'ou l'erreur mais j'avais pas les yeux pour voir mon erreur un grand merci

    vendredi 4 mai 2018 00:51