Public/Get-specTonorefUrl.ps1
Function Get-specTonorefUrl { <# .SYNOPSIS Generates URLs for accessing Tonoref devices. .DESCRIPTION Constructs URLs for accessing Nidek or Heidelberg spectralis tonoref devices on a network. It takes a Tonoref code, EPOS number, and an optional HTTPS flag as input and returns custom objects containing the URL and EPOS. .PARAMETER Tonoref Mandatory parameter. A valid Tonoref code (e.g., 'n1', 'h2') specifying the device type. .PARAMETER EPOS Mandatory parameter. The EPOS number uniquely identifies the device. .PARAMETER HTTPS Optional switch parameter. If present, constructs a secure (HTTPS) URL instead of regular HTTP. .EXAMPLE # Single item, HTTPS get-specTonorefUrl -EPOS 1234 -Tonoref n2 -HTTPS .EXAMPLE # Pipeline with custom objects $items = @( [pscustomobject]@{EPOS = '1992'; Tonoref = 'n1' } [pscustomobject]@{EPOS = '0277'; Tonoref = 'h3' } ) $items | get-specTonorefUrl .EXAMPLE # Pipeline with hashtables (converted to custom objects) $items = @( @{EPOS = '5678'; Tonoref = 'n2' } @{EPOS = '1234'; Tonoref = 'h1' } ) $items | ForEach-Object { [pscustomobject]$_ } | get-specTonorefUrl .EXAMPLE # Pipeline with hashtables (direct processing) $items = @( @{EPOS = '5678'; Tonoref = 'n2' } @{EPOS = '1234'; Tonoref = 'h1' } ) $items | % { Get-specTonorefUrl -Tonoref $_.Tonoref -EPOS $_.epos } .NOTES Author: owen.heaume Version: - 1.0.0 Initial release - 1.0.1 Changed logic for URL generation #> [cmdletbinding()] Param( [Parameter(Mandatory, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [ValidateSet('n1', 'n2', 'n3', 'h1', 'h2', 'h3')] [string]$Tonoref, # Nidek = 2, HB = 1 [Parameter(Mandatory, ValueFromPipelineByPropertyName = $true)] [string]$EPOS, [Switch]$HTTPS ) Begin { # The last digit of the port is dynamically added based on the last character of the $Tonoref variable [int]$port = 810 } Process { foreach ($t in $Tonoref) { # 1. Get the 'Y' value for the URL Switch ($t[0]) { 'N' { $Y = '2' } 'H' { $Y = '1' } } # 2. Build the last digit of the port number based on the last character of the $Tonoref variable and subtract 1 $portDigit = [int]($t[1].ToString()) - 1 # 3. Build the URL if ($HTTPS.IsPresent) { [PSCustomObject]@{ Url = "https://rgbr" + $EPOS + "v" + $Y + "2.re.ad.specsavers.com:" + $port + $portDigit EPOS = $EPOS } } else { [PSCustomObject]@{ Url = "http://rgbr" + $EPOS + "v" + $Y + "2.re.ad.specsavers.com:" + $port + $portDigit EPOS = $EPOS } } } } End { } } |