?
Solved

prompt for powershell for user inputbox

Posted on 2014-07-14
6
Medium Priority
?
1,529 Views
Last Modified: 2014-07-15
Greetings I am trying to construct a prompt for an inputbox that will prompt me for the input and then run this script and have it to go into the csv file. I am trying to Microsoft.visual basic parameters and they are not working. I am using powershell 3.0. The $prompto variable after organizationalname is the piece I am trying to get an inputbox to prompt for thanks. Any help would be appreciated.


$Total_results=@()
$mailbox=Get-mailbox –organizationalname $prompto
$mailbox| foreach-object{
$DisplayName=$_.DisplayName
$SmtpAddress=$_.PrimarySmtpAddress
$TotalItemSize=(get-mailboxstatistics –identity $DisplayName ).TotalITemSize
$ItemCount=(get-mailboxstatistics -identity $DisplayName ).ItemCount


$obj=new-object System.Object

$obj|add-member -membertype NoteProperty -name "PrimarySmtpAddress" -value $SmtpAddress

$obj|add-member -membertype NoteProperty -name "TotalItemSize" -value $TotalItemSize

$obj|add-member -membertype NoteProperty -name "ItemCount" -value $ItemCount

$Total_results+=$obj

}

$Total_results|export-csv c:\report.csv -notype
0
Comment
Question by:techdrive
6 Comments
 
LVL 44

Expert Comment

by:Amit
ID: 40194325
Though PS is easy to use, however when it comes to GUI, it is a complex task. Check below MS URL
http://technet.microsoft.com/en-us/library/ff730941.aspx

See if this fits to your requirement.
0
 
LVL 41

Expert Comment

by:footech
ID: 40194344
If you're fine with just a prompt at the console, then you can use Read-Host.
$prompto = Read-Host "Enter something"
If you really need a popup box then you're left with the more complicated route of creating GUI elements.
0
 
LVL 7

Expert Comment

by:Murali Reddy
ID: 40194382
$prompto = read-host                           ####and then
$mailbox=Get-mailbox –organizationalname $prompto -resultsize "unlimited"

or

$mailbox=Get-mailbox –organizationalname (read-host) -resultsize "unlimited"


May I have your requirement? Howmany exchange organizations you have in your setup?
0
What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 1000 total points
ID: 40194399
For a non-GUI, simple prompt you can use $promptTo = read-host 'Please provide the organizational unit to display members of'.

The code you showed isn't the way you should write PowerShell scripts. Make extensive use of the pipeline, as this improves both performance and memory consumption. Where you should use intermediate vars is if you need to use data more than once; you called get-mailboxstatistics twice, which should be avoided.
$promptTo = read-host 'Please provide the organizational unit to display mailboxes of'
Get-mailbox –organizationalname $prompto | foreach-object {
  $mbstats       = get-mailboxstatistics –identity $_.DisplayName

  new-object PsObject -Property @{
     PrimarySmtpAddress = $_.PrimarySmtpAddress
     TotalItemSize      = $mbstats.TotalITemSize
     ItemCount          = $mbstats.ItemCount
  }
} | export-csv c:\report.csv -notype

Open in new window

This can be written more smart even, by using the mailbox statistics object and filter/add properties as needed:
$promptTo = read-host 'Please provide the organizational unit to display mailboxes of'
Get-mailbox –organizationalname $prompto | foreach-object {
  $SmtpAddress = $_.PrimarySmtpAddress
  get-mailboxstatistics –identity $_.DisplayName |
    select TotalItemSize, ItemCount, @{n='PrimarySmtpAddress'; e={$SmtpAddress}}
} | export-csv c:\report.csv -notype

Open in new window

We have still to use foreach-object here since PrimarySmtpAddress isn't contained in the mb stats (the display name is for example).
0
 
LVL 85

Accepted Solution

by:
oBdA earned 1000 total points
ID: 40196280
For what it's worth, it's actually not that difficult to access the VB Inputbox in PS:
Add-Type -AssemblyName Microsoft.VisualBasic
$prompto = [Microsoft.VisualBasic.Interaction]::InputBox("Prompt", "Title", "Default Response")

Open in new window

0
 

Author Comment

by:techdrive
ID: 40196942
outstanding thanks exactly what I was looking for OBDA
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

How to effectively resolve the number one email related issue received by helpdesks.
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
Screencast - Getting to Know the Pipeline
Suggested Courses

839 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