短くできたw

if ('20210531285930' -match '(¥d{8})(¥d¥d)(¥d¥d)(¥d¥d)') {
$date = [datetime]::ParseExact($Matches[1],'yyyyMMdd', $null)
$date = $date.AddSeconds(3600 * $Matches[2] + 60 * $Matches[3] + $Matches[4])
}