Solved

How to format input entry in powershell ?

Posted on 2013-01-11
3
266 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

Independent Software Vendors: 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!

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

627 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