marabunta

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."  
        }
    }
}
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 347218

Url: https://administrator.de/forum/powershell-mehrere-try-catch-bloecke-347218.html

Ausgedruckt am: 15.05.2025 um 09:05 Uhr

133883
133883 24.08.2017 aktualisiert um 19:30:14 Uhr
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ß