Author Posts

June 25, 2015 at 6:33 am

I'm after some help (again) I'm getting a text file updated with a port number by a gui box for the end user. I only want a max of 3 digits in totally and each one can only range from 0-9. What can i do ? the \d says its a digit ...got that far !

June 25, 2015 at 6:37 am

This looks like it might work...

"^\d{3}$"

June 25, 2015 at 6:45 am

Cracked it !!!

do {
$AAHelpDirectory = 'C:\AAHelp\tmp\port.cfg'
$CurrentPort = get-content "C:\AAHelp\tmp\port.cfg"
[int]$NewPortNumber = [Microsoft.VisualBasic.Interaction]::InputBox("`nPort is currently set to $CurrentPort `n`n`n`n`nPlease Enter the new port number", "AAHELP PORT MANAGER") 
   }
Until ($NewPortNumber -match "^\d{3}$")

June 25, 2015 at 7:07 am

The final script looked like this, if your interested ! 🙂

 
 
#Add .NET assembly for GUI box  
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null

#Run 
do {
#Set AAHelp port.cfg location
$AAHelpDirectory = 'C:\AAHelp\tmp\port.cfg'
#Check current port number
$CurrentPort = get-content "C:\AAHelp\tmp\port.cfg"
#Run GUI box and request new 3 digit number
[int]$NewPortNumber = [Microsoft.VisualBasic.Interaction]::InputBox("`nPort is currently set to $CurrentPort `n`n`n`nPlease Enter the new port number `n(ONLY 3 Digits)", "AAHELP PORT MANAGER") 
   }
#Loop until 3 digit number is supplied
Until ($NewPortNumber -match "^\d{3}$")

#Update port.cfg file
Set-Content -Path $AAHelpDirectory -Value $NewPortNumber