Schedule Exchange mailbox permissions?

Exchange Server 2010 - soon upgrading to 2013

So I get mad requests all the time in my environment for temporary mailbox permissions.
"Hey Tuesday Bob needs mailbox access to Susan"
"Hey Thursday, Susan needs access to Bob"

These requests are so annoying and it's a nightmare trying to add mailbox and send-as permissions manually every time.
I use Powershell and a csv file to help process it (identity, user columns, and adding permissions).

But is there a way to automate the processing of a script that will remove their permissions?

is there another program or web-based feature that makes scheduling easier for mailbox permission processing and permission-removal processing?
garryshapeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe KlimisCommented:
Hi

I have created the following, but i have been unable to test it as I don't currently have access to a suitable environment.

The script requires 3 parameters and can be invoked in the following way

 & '.\scriptname.ps1' -TargetMailbox sharedmbxUser -user managerMbxUser -Retraction 21-dec-2014

Open in new window


The script will
add the permissions
and create a scheduled job which will remove the permissions on the allotted date.

you will need to update "YourDomain\YourUser"  with suitable credentials, and will need to be created on an exchange server , or workstation with the tools installed.

let me know how you get on

Regards
Joe


#
#
#
Param([string]$TargetMailbox =$(throw "TargetMailbox ? "),
[string]$user =$(throw "User to give Access to. "),
[datetime]$Retraction = (get-date).adddays(30) #  remove after 30 days by default
)
#
#  set credentials to be used.
#
$creds = Get-Credential YourDomain\YourUser

#
# Adding Exchange Snap In to execute Exchange CmdLets in this script
#
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

# add the permissions to the mailbox
Add-MailboxPermission    -Identity $TargetMailbox -User $user -AccessRights Fullaccess -InheritanceType all

#
# create a scheduled job and the specified date ti remove the permissions.
#
$RemoveCmd = "Remove-MailboxPermission -Identity $TargetMailbox -User $user -AccessRights Fullaccess -InheritanceType all"
$trigger = New-JobTrigger -Once -At $retraction

#
# setup the scheduled job
#
$sjo = New-ScheduledJobOption -RunElevated
$del_mailbox_perms={
param ([string]$removeCmd)
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; invoke-expression $removeCmd"
}
#$name = "$(get-date $Retraction -format 'yyyymmdd')"
$name = "MailBox_Permission_remove_$($user)_from_$($Targetmailbox)"
Register-ScheduledJob -Name $name -ArgumentList $removeCmd -ScriptBlock $del_mailbox_perms   -Trigger $trigger `
 -Credential $creds `
 -ScheduledJobOption $sjo
 

Open in new window

0
garryshapeAuthor Commented:
Hi Joe, thanks, I'm assuming the code at the bottom is what would be saved as the scriptname.ps1 in your example, right?
0
garryshapeAuthor Commented:
Yeah it looks like the New-JobTrigger won't work for me because I'm on Exchange 2010. Don't think I can upgrade to Powershell 3 or 4 on that server.
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

garryshapeAuthor Commented:
Do you know how then, I could with a GUI script running these two commands:    
	Add-MailboxPermission $Identity -User $User -Access "FullAccess" -confirm: $false
	Add-ADPermission -Identity $Identity -User $User -AccessRights ExtendedRight -ExtendedRights "send as"

Open in new window


output the commands into the output console window so I can tell if they worked or not?
The commands run when I click the button I made to process it in the GUI (winforms), but I'm not sure how to get the output shown into the console.
0
garryshapeAuthor Commented:
I tried appending -verbose but it's way too much information
0
garryshapeAuthor Commented:
It looks like the output types for the cmdlets are ADAcePresentationObject and MailboxAcePresentationObject
0
garryshapeAuthor Commented:
I guess I could append "| select IsValid" to get the boolean true/false and write-host or change GUI accordingly?
0
garryshapeAuthor Commented:
Hi disregard I used a Try Catch and it worked
0
Joe KlimisCommented:
Hi

The easy way to build a gui is to use the Admin Script editor , it allows you to build windows forms using a gui tool , and generates the Powershell for you .

Its very cool and free and can be downloaded from

http://www.itninja.com/community/admin-script-editor


Here is one i created   you may find useful as an example. it just  does simple weight conversion.

#region Script Settings
#<ScriptSettings xmlns="http://tempuri.org/ScriptSettings.xsd">
#  <ScriptPackager>
#    <process>powershell.exe</process>
#    <arguments />
#    <extractdir>%TEMP%</extractdir>
#    <files />
#    <usedefaulticon>true</usedefaulticon>
#    <showinsystray>false</showinsystray>
#    <altcreds>false</altcreds>
#    <efs>true</efs>
#    <ntfs>true</ntfs>
#    <local>false</local>
#    <abortonfail>true</abortonfail>
#    <product />
#    <version>1.0.0.1</version>
#    <versionstring />
#    <comments />
#    <company />
#    <includeinterpreter>false</includeinterpreter>
#    <forcecomregistration>false</forcecomregistration>
#    <consolemode>false</consolemode>
#    <EnableChangelog>false</EnableChangelog>
#    <AutoBackup>false</AutoBackup>
#    <snapinforce>false</snapinforce>
#    <snapinshowprogress>false</snapinshowprogress>
#    <snapinautoadd>2</snapinautoadd>
#    <snapinpermanentpath />
#    <cpumode>1</cpumode>
#    <hidepsconsole>false</hidepsconsole>
#  </ScriptPackager>
#</ScriptSettings>
#endregion

#region ScriptForm Designer

#region Constructor

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

#endregion

#region Post-Constructor Custom Code

#endregion

#region Form Creation
#Warning: It is recommended that changes inside this region be handled using the ScriptForm Designer.
#When working with the ScriptForm designer this region and any changes within may be overwritten.
#~~< Form1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$Form1 = New-Object System.Windows.Forms.Form
$Form1.ClientSize = New-Object System.Drawing.Size(287, 172)
$Form1.Text = "Weight Convert V1.0"
$Form1.BackColor = [System.Drawing.SystemColors]::InactiveCaption
#~~< RadioButtonLb >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$RadioButtonLb = New-Object System.Windows.Forms.RadioButton
$RadioButtonLb.Location = New-Object System.Drawing.Point(177, 63)
$RadioButtonLb.Size = New-Object System.Drawing.Size(104, 24)
$RadioButtonLb.TabIndex = 7
$RadioButtonLb.TabStop = $true
$RadioButtonLb.Text = "Pounds to KG"
$RadioButtonLb.UseVisualStyleBackColor = $true
$RadioButtonLb.add_Click({RadioButtonLbClick($RadioButtonLb)})
#~~< RadioButtonkg >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$RadioButtonkg = New-Object System.Windows.Forms.RadioButton
$RadioButtonkg.Location = New-Object System.Drawing.Point(177, 41)
$RadioButtonkg.Size = New-Object System.Drawing.Size(95, 24)
$RadioButtonkg.TabIndex = 6
$RadioButtonkg.TabStop = $true
$RadioButtonkg.Text = "kg to Pounds"
$RadioButtonkg.UseVisualStyleBackColor = $true
$RadioButtonkg.add_Click({RadioButtonkgClick($RadioButtonkg)})
#~~< TextBox2 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TextBox2 = New-Object System.Windows.Forms.TextBox
$TextBox2.Location = New-Object System.Drawing.Point(12, 109)
$TextBox2.ReadOnly = $true
$TextBox2.Size = New-Object System.Drawing.Size(131, 20)
$TextBox2.TabIndex = 4
$TextBox2.Text = ""
#~~< TextBox1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TextBox1 = New-Object System.Windows.Forms.TextBox
$TextBox1.Location = New-Object System.Drawing.Point(7, 67)
$TextBox1.Size = New-Object System.Drawing.Size(136, 20)
$TextBox1.TabIndex = 3
$TextBox1.Text = ""
$TextBox1.add_TextChanged({TextBox1TextChanged($TextBox1)})
#~~< Label1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$Label1 = New-Object System.Windows.Forms.Label
$Label1.Location = New-Object System.Drawing.Point(33, 8)
$Label1.Size = New-Object System.Drawing.Size(150, 30)
$Label1.TabIndex = 2
$Label1.Text = "Powershell Converter"
#~~< btn_convert >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$btn_convert = New-Object System.Windows.Forms.Button
$btn_convert.Location = New-Object System.Drawing.Point(177, 93)
$btn_convert.Size = New-Object System.Drawing.Size(104, 36)
$btn_convert.TabIndex = 1
$btn_convert.Text = "Convert"
$btn_convert.UseVisualStyleBackColor = $true
$btn_convert.add_Click({Btn_convertClick($btn_convert)})
#~~< btn_quit >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$btn_quit = New-Object System.Windows.Forms.Button
$btn_quit.Location = New-Object System.Drawing.Point(177, 145)
$btn_quit.Size = New-Object System.Drawing.Size(75, 23)
$btn_quit.TabIndex = 0
$btn_quit.Text = "Quit"
$btn_quit.UseVisualStyleBackColor = $true
$btn_quit.add_Click({Btn_quitClick($btn_quit)})
$Form1.Controls.Add($RadioButtonLb)
$Form1.Controls.Add($RadioButtonkg)
$Form1.Controls.Add($TextBox2)
$Form1.Controls.Add($TextBox1)
$Form1.Controls.Add($Label1)
$Form1.Controls.Add($btn_convert)
$Form1.Controls.Add($btn_quit)

#endregion

#region Custom Code

#endregion

#region Event Loop

function Main{
	[System.Windows.Forms.Application]::EnableVisualStyles()
	[System.Windows.Forms.Application]::Run($Form1)
}

#endregion

#endregion

#region Event Handlers

function RadioButtonLbClick( $object ){
	$RadioButtonkg.checked=$false
	$RadioButtonLb.checked=$true
}

function RadioButtonkgClick( $object ){
	$RadioButtonkg.checked = $true
	$RadioButtonLb.checked = $false
}

function Btn_convertClick($object)
{
	if ($RadioButtonkg.checked )
	{ $TextBox2.Text = [single]($TextBox1.Text) * 2.2046226218 }
		
	else
	{ $TextBox2.Text = [single]($TextBox1.Text) / 2.2046226218  }
	

}

function Btn_quitClick( $object ){
$Form1.close()
}

function TextBox1TextChanged( $object ){

}

Main # This call must remain below all other event functions

#endregion

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
garryshapeAuthor Commented:
Well I'm using Sapien but now they got rid of the free Community edition and want me to pay over $300 to be able to create more than 5 elements on a form lol.
0
garryshapeAuthor Commented:
Thanks sorry one last question

For a combobox, I made the drop-down menu this command:

$displayNames = get-mailbox -ResultSize Unlimited | select Name | Sort Name
$ComboBox1.Items.AddRange($displayNames)

Open in new window


It loads ok but when I click the Combobox menu, I see all the display names, but everyone's display name has a "@{Name=" before their name, and a "}" at the end.
Do it looks like:
@{Name=John Smith}

instead of just John Smith like it should :( any ideas?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.