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
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
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."
}
}
}
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 347218
Url: https://administrator.de/forum/powershell-mehrere-try-catch-bloecke-347218.html
Ausgedruckt am: 16.04.2025 um 17:04 Uhr
1 Kommentar

Ziemlich umständlich 
Oneliner
Gruß
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){$_}}