Solved

Powershell script

Posted on 2016-11-03
9
81 Views
Last Modified: 2016-11-23
Requirements of the script:

Input: Display name, alias or SMTP address of a mailbox
Output:  Can be selected by user which is one of the properties of the command "Get-Mailbox -Identity <username> |fl "

Example for Output selection by user: ExtensionCustomAttribute1
0
Comment
Question by:Exchange Admin
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 14

Expert Comment

by:Jason Crawford
ID: 41873503
I'm trying to understand what the requirements are and I'm having a hard time.  Do you need a GUI?  Should a list of all possible parameters for Get-Mailbox exist in something like a drop down menu?
0
 
LVL 7

Expert Comment

by:Andy
ID: 41873705
Hi,

As a basic script you can do something like this:
$UserInputName = Read-Host "`t`tPlease enter the user displayname"
$AttributeInput = Read-Host "`t`tPlease enter the required attribute"
get-mailbox -identity $UserInputName | select $AttributeInput
0
 
LVL 7

Assisted Solution

by:Andy
Andy earned 250 total points
ID: 41873828
Hi

I've updated with the other requirements for you.
This is all using the Exchange Shell, hence the import of the AD module
*****
Import-Module ActiveDirectory

DisplayName
$UserDispName = Read-Host "`t`tPlease enter the user displayname"
$AttributeInput = Read-Host "`t`tPlease enter the required attribute"
get-mailbox -identity $UserInputName | select $AttributeInput


Alias
$userAlias = Read-Host "`t`tPlease enter the user Alias"
$UserADAlias = Get-ADUser -Filter {mailNickName -eq $userAlias} | %{$_.SamAccountName}
$AttributeInput = Read-Host "`t`tPlease enter the required attribute"
get-mailbox -identity $UserADAlias | select $AttributeInput


SMTP
$usermail = Read-Host "`t`tPlease enter the user e-mail address"
$UserADName = Get-ADUser -Filter {Emailaddress -eq $usermail} | %{$_.SamAccountName}
$AttributeInput = Read-Host "`t`tPlease enter the required attribute"
get-mailbox -identity $UserADName | select $AttributeInput
*****
0
 
LVL 4
ID: 41874948
I read like Jason did.  Needing a GUI?   Close as I can get.

# GUI version using Input Box.  This is for the alias.

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
	$ClientUser = [Microsoft.VisualBasic.Interaction]::InputBox("Please enter users alias", "Enter")

	Get-Mailbox -Filter * -Identity $clientUser -ResultSize unlimited | select name, customattribute1 |Out-GridView

Open in new window

0
[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

 

Author Comment

by:Exchange Admin
ID: 41875145
Hi Todd and Jason,

Thanks for your response. The requirement is a powershell script which should meet the below criteria:

      An excel file with a set of users (which could be either email address or alias or display name) is provided to script during its run time as input.
     Script should prompt user to select the output which could be any attributes of Get-mailbox command result. And the selection of user can be one or many
    If mailbox is not present, output should be "Not found"

Please check the attachment.

Regards,
Sindhura
Mailbox.xlsx
0
 
LVL 14

Expert Comment

by:Jason Crawford
ID: 41875362
Just to make sure I'm on the same page.  A .csv file containing one column populated with rows of users will be provided.  The script should import the list of users, then display a full list of all parameters for the Get-Mailbox cmdlet (I'm guessing a numbered list).  The user will enter the number mapped to the parameter they want included in the output.  For each user in the .csv file the script will run Get-Mailbox and gather the pre-selected parameters.  I assume you want the output to be a ,csv file on the desktop?  Is that all right?
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 250 total points
ID: 41875505
We can use Excel - if really needed. But it is not recommended, as access is slow. Better, and probably what you really want, is the use of CSV files as Jason mentioned above. Though using a single column CSV is overkill; you usually leave out the column header and store as text file then.

Mixing CSV in/output with an interactive grid view for the attributes choice (even allowing for selecting multiple attributes):
$attr = '*'
$forcedAttr = 'DisplayName', 'UserPrincipalName', 'Database', 'WhenCreated'
Import-CSV C:\Temp\EE\Users.csv |
  % {
    $mb = Get-Mailbox $_.{Display Name} -Filter $attr
    if ($attr -eq '*')   # we need to show an attribute choice opportunity once
    {
      $attr = $mb | Get-Member -Type Property | Select Name |
                    ? { $forcedAttr -notcontains $_.Name } | 
                    Out-GridView -OutputMode Multiple -Title "Select attributes to export"
      $attr = $forcedAttr + $attr
    }
    $mb | select $attr  
  } |
  Export-CSV -NoType C:\Temp\EE\Results.csv

Open in new window

With some more effort we can display example values (of the first mailbox) when showing the grid, or exclude attributes which should never be exportable.
0
 

Author Comment

by:Exchange Admin
ID: 41876216
Hi Jason,

You are correct, but the output selection by user is not a number. User can enter the parameter required by them during run of script. And this parameter can be one or many.

Regards,
Sindhura
0
 

Author Closing Comment

by:Exchange Admin
ID: 41899024
Solutions were provided
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

15 Experts available now in Live!

Get 1:1 Help Now