Skrypt jest podany poniżej:
function Get-OracleHelp { param( [ValidateNotNullOrEmpty()] [Alias('code')] [string]$errorCode ) [ref]$errorNumber=0 $isNumber = [int]::TryParse($errorCode, $errorNumber) if($isNumber) { $errorCode = 'ORA-{0:00000}' -f $errorNumber.Value } $errorCode = $errorCode.ToUpper() $url = "http://{0}.ora-code.com/" -f $errorCode $request = Invoke-WebRequest -Uri $url -UseDefaultCredentials $table = $request.ParsedHtml.body.getElementsByTagName('table') $trs = $table | %{$_.getElementsByTagName('tr')} | ? {$_.getAttributeNode('valign').value -eq 'top' } $desc='' $cause='' $action='' $trs | %{ [string]$text = $_.innerText if( $text.StartsWith($errorCode, 'CurrentCultureIgnoreCase')) { $desc = $text.Remove(0, $errorCode.Length+1) } if( $text.StartsWith('Cause', 'CurrentCultureIgnoreCase')) { $cause = $text.Remove(0, 'Cause'.Length+1) } if( $text.StartsWith('Action', 'CurrentCultureIgnoreCase')) { $action = $text.Remove(0, 'Action'.Length+1) } } return new-object PSObject ` | Add-Member -MemberType NoteProperty -PassThru -Name 'Code' -Value $errorCode ` | Add-Member -MemberType NoteProperty -PassThru -Name 'Description' -Value $desc ` | Add-Member -MemberType NoteProperty -PassThru -Name 'Cause' -Value $cause ` | Add-Member -MemberType NoteProperty -PassThru -Name 'Action' -Value $action ` | Add-Member -MemberType NoteProperty -PassThru -Name 'Url' -Value $url }Wywołanie wygląda następująco:
Get-OracleHelp -errorCode ORA-01243I dostajemy taki opis błędu:
Oprócz całego kodu błedu to można wpisać tylko numer błędu:
Get-OracleHelp -code 12154
Brak komentarzy:
Prześlij komentarz