dimanche 17 février 2019

Powershell test 2 statements if true functions

Clear-Host

Function First {

$File1 = "C:\Program Files\WinRAR\WinRAR.exe"

$TestFile1 = Test-Path $File1

If ($TestFile1 -eq $True) {Write-Host "Winrar is installed." -F Green -B Black}

Else {Write-Host "Winrar is not installed." -F Red -B Black}

} First

Function Second {

$winrar = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion \Uninstall*

$winrarCheck = "Winrar"

$winrarFinal = $winrar | Where {$_.DisplayName -match $winrarCheck} | Format-

Table -Property DisplayName,DisplayVersion

$winrarFinal

If ($winrarFinal) {Write-Host "Winrar registry check installed." -F Green -B Black}

Else {Write-Host "Winrar registry check failed." -F Red -B Black}

} Second

Is there a way to check both functions with If statement? I want to check it like if both functions are true, Write-Host "Program installed." Else Write-Host "Failed to install".

Aucun commentaire:

Enregistrer un commentaire