Solved

How to format input entry in powershell ?

Posted on 2013-01-11
3
261 Views
Last Modified: 2013-01-12
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
Comment
Question by:namerg
  • 2
3 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 38769300
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
 

Author Comment

by:namerg
ID: 38769316
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
 
LVL 68

Expert Comment

by:Qlemo
ID: 38769861
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
This article will help you understand what HashTables are and how to use them in PowerShell.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now