Function Powershell test 2语句(如果函数为true)

Function Powershell test 2语句(如果函数为true),function,powershell,if-statement,Function,Powershell,If Statement,有没有办法用If语句检查这两个函数?我想检查一下,如果这两个函数都是真的, 写入主机“程序已安装。”否则写入主机“安装失败”。我们开始: 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 G

有没有办法用If语句检查这两个函数?我想检查一下,如果这两个函数都是真的,
写入主机“程序已安装。”否则写入主机“安装失败”。

我们开始:

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

嗨,先生,请你解释一下这句话好吗?return($testFileProg-或$x86-或$x64)如果其中一个为true,则函数返回true是否有方法使其中两个为true,返回true?我需要$testfileProg为true,并且$x86或$x64return($testfileProg-和($x86-或$x64))中的1是F6a4,这部分代码有什么原因吗。长度-gt 0;?
Function CheckFileInstalled {

    param (
        [string]$pathProg     = "C:\Program Files\WinRAR\WinRAR.exe",
        [string]$nameProg     = "Winrar"
    )

    $testFileProg = Test-Path $pathProg

    $x86 = ((Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall") |
        Where-Object { $_.GetValue( "DisplayName" ) -like "*$nameProg*" } ).Length -gt 0;

    $x64 = ((Get-ChildItem "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") |
        Where-Object { $_.GetValue( "DisplayName" ) -like "*$nameProg*" } ).Length -gt 0;


    return ( $testFileProg -and ($x86 -or $x64) )

}


if( CheckFileInstalled ) {

    Write-Host "Program installed." 
}
else {
    Write-Host "Failed to install."
}