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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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-ID: 347218

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

Ausgedruckt am: 16.04.2025 um 17:04 Uhr

133883
133883 24.08.2017 aktualisiert um 19:30:14 Uhr
Goto Top
Ziemlich umständlich face-smile

Oneliner
1
$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ß