marabunta
Goto Top

PowerShell mehrere Try-Catch Blöcke?

Hallo,

ich versuche den Steam-Pfad herauszufinden und möchte eure Meinung dazu. Sind hier mehrere Try-Catch Blöcke sinnvoll oder eine andere Methode?
Danke

Function STEAMPATH{
    try{
        $Global:STEAMPATH_REGISTRY=Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Valve\Steam" -Name InstallPath | Select -ExpandProperty InstallPath  
        Test-Path $Global:STEAMPATH_REGISTRY
    }
    catch{
        try{
            $Global:STEAMPATH_REGISTRY=Get-ItemProperty -Path "HKLM:\SOFTWARE\Valve\Steam" -Name InstallPath | Select -ExpandProperty InstallPath  
            Test-Path $Global:STEAMPATH_REGISTRY
        }catch{
            Write-Output "Not found."  
        }
    }
}

Content-Key: 347218

Url: https://administrator.de/contentid/347218

Printed on: April 26, 2024 at 12:04 o'clock

Mitglied: 133883
133883 Aug 24, 2017 updated at 17:30:14 (UTC)
Goto Top
Ziemlich umständlich face-smile

Oneliner
$Global:STEAMPATH_REGISTRY = "HKLM:\SOFTWARE\WOW6432Node\Valve\Steam" ,"HKLM:\SOFTWARE\Valve\Steam" | %{if (Get-ItemProperty -Path $_ -Name Path -EA 0 | Select -ExpandProperty InstallPath | Test-Path){$_}}  
Gruß