Solved

Powershell script

Posted on 2016-11-03
9
89 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
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.

 
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
 

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 69

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

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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