Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for asc.ps

(view source code of asc.ps as plain text)

  1. function Syntax {
  2.     Write-Host
  3.     Write-Host "Asc.ps1,  Version 1.00"
  4.     Write-Host "Returns the numeric ASCII value for the specified character"
  5.     Write-Host
  6.     Write-Host "Usage:   " -NoNewline
  7.     Write-Host "ASC.PS1  char" -ForegroundColor White
  8.     Write-Host
  9.     Write-Host "Returns: Numeric ASCII value of " -NoNewline
  10.     Write-Host "char" -ForegroundColor White
  11.     Write-Host
  12.     Write-Host "Notes:   The ASCII value is written to Standard Output (usually the screen)"
  13.     Write-Host "         as well as returned as `"errorlevel`""
  14.     Write-Host "         If more than 1 character is passed on the command line, only the first"
  15.     Write-Host "         character will be used, the remainder of the string will be ignored."
  16.     Write-Host "         The `"errorlevel`" will equal the ASCII value, or 0 if no parameter"
  17.     Write-Host "         was passed, or -1 in case of errors or for this help"
  18.     Write-Host
  19.     Write-Host "Credits: Code to pass exit code as `"errorlevel`" to the calling batch file"
  20.     Write-Host "         or PowerShell script by Serge van den Oever:"
  21.     Write-Host "         weblogs.asp.net/soever/returning-an-exit-code-from-a-powershell-script" -ForegroundColor DarkGray
  22.     Write-Host
  23.     Write-Host "Written by Rob van der Woude"
  24.     Write-Host "http://www.robvanderwoude.com"
  25.  
  26.     $Host.SetShouldExit( -1 )
  27.     Exit
  28. }
  29.  
  30. if ( $args.Length -eq 1 ) {
  31.     if ( $args[0] -eq "/?" ) {
  32.         Syntax
  33.     } else {
  34.         $input = $args[0]
  35.     }
  36. } else {
  37.     Syntax
  38. }
  39.  
  40. if ( $input -eq "" ) { $input = [string][char]0 }
  41.  
  42. [char]$char = $input[0]
  43.  
  44. Write-Host ([byte]$char) -NoNewline
  45.  
  46. # Pass exit code to calling batch or PowerShell script, by Serge van den Oever
  47. # https://weblogs.asp.net/soever/returning-an-exit-code-from-a-powershell-script
  48. $Host.SetShouldExit( [byte]$char )
  49. Exit
  50.  

page last modified: 2024-04-16; loaded in 0.0102 seconds