Solved

How to format input entry in powershell ?

Posted on 2013-01-11
3
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

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 70

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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