if($filetype-eq"log"){# First attempt$filepath=$server.DefaultLog# Second attemptif($filepath.Length-eq0){$filepath=$server.Information.MasterDbLogPath}# Third attemptif($filepath.Length-eq0){$sql="select SERVERPROPERTY('InstanceDefaultLogPath') as physical_name"$filepath=$server.ConnectionContext.ExecuteScalar($sql)}}else{# First attempt$filepath=$server.DefaultFile# Second attemptif($filepath.Length-eq0){$filepath=$server.Information.MasterDbPath}# Third attemptif($filepath.Length-eq0){$sql="select SERVERPROPERTY('InstanceDefaultDataPath') as physical_name"$filepath=$server.ConnectionContext.ExecuteScalar($sql)}}