prompt for powershell for user inputbox

Posted on 2014-07-14
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.

$mailbox=Get-mailbox –organizationalname $prompto
$mailbox| foreach-object{
$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|export-csv c:\report.csv -notype
Question by:techdrive
    LVL 41

    Expert Comment

    Though PS is easy to use, however when it comes to GUI, it is a complex task. Check below MS URL

    See if this fits to your requirement.
    LVL 38

    Expert Comment

    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.
    LVL 7

    Expert Comment

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


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

    May I have your requirement? Howmany exchange organizations you have in your setup?
    LVL 67

    Assisted Solution

    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).
    LVL 82

    Accepted Solution

    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


    Author Comment

    outstanding thanks exactly what I was looking for OBDA

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
    Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
    The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    755 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

    22 Experts available now in Live!

    Get 1:1 Help Now