Solved

How to format input entry in powershell ?

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

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 69

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
A procedure for exporting installed hotfix details of remote computers using powershell
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…

821 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