Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

How to format input entry in powershell ?

Hello,

I need to change telephone number in AD, and I have the code for that, but just wondering how to format the input.

I ask  "Type the new TELEPHONE Number:" it will be nice to be something like

Type the new TELEPHONE Number:    -   -

then user types
Type the new TELEPHONE Number: 303-333-3333

So between : and - there are 4 spaces and 3 spaces between - and -

The code I have is
$InputTelephoneNumber = Read-Host 'Type the new TELEPHONE Number'

Open in new window


Is it possible ?
0
namerg
Asked:
namerg
  • 2
1 Solution
 
QlemoC++ DeveloperCommented:
No. PowerShell's read-host does not allow for that much of control. The only way to handle that in a console window is to ask for the input as a whole, and then apply different formatting options on the input (like removing or adding dashes).
0
 
namergSystems AdministratorAuthor Commented:
Hmm, thank you Qlemo.

And how do i add the different formatting options to the input and I specify in my question?

Thanks for your help.
0
 
QlemoC++ DeveloperCommented:
That depends on what you want to allow and what should be stored in AD exactly.
You can e.g. remove all dashes and spaces:
   $phone = $inputTelephoneNumber.Replace(' ', '').Replace('-', '')
and then reformat:
   $phone = $phone.Insert(6,'-').Insert(3,'-')
to get 303-333-3333.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now