Script to enable-mailbox and choose correct mailbox and archive database - Exchange 2010
first let me preface saying bulk of script (drop down menu) grabbed http://www.powershell.nu/2009/01/21/dropdown-menu-using-windowsforms/
here script stands...
my goal this: have script prompt username of user needs mailbox enabled. next site chosen drop down menu.
here kicker.. rather defining site codes have done below (dfw, sea, etc) grab csv.
i need csv include associated datastore name , online archive name.
so csv this
site datastore archive
dal mbstore01 oastore01
i'm trying away if commands @ bottom of script (they in bold). keep info stored directly in csv
any ideas? appreciated!!
---start script---
add-pssnapin microsoft.exchange.management.powershell.e2010
# enter user name
$identity = read-host "enter user name of mailbox enable (ex: domain\user)"
$alias =
######### drop down menu choose site ############
# edit item change dropdown values
[array]$dropdownarray =
"dal",
"cam",
"far / lhn",
"nyc",
"dal(gst)",
"sea",
"gst"
# function returns selected value , closes form
function return-dropdown {
$choice = $dropdown.selecteditem.tostring()
$form.close()
write-host $choice
}
[system.reflection.assembly]::loadwithpartialname("system.windows.forms")
[system.reflection.assembly]::loadwithpartialname("system.drawing")
$form = new-object system.windows.forms.form
$form.width = 300
$form.height = 150
$form.text = ”dropdown”
$dropdown = new-object system.windows.forms.combobox
$dropdown.location = new-object system.drawing.size(100,10)
$dropdown.size = new-object system.drawing.size(130,30)
foreach ($item in $dropdownarray) {
$dropdown.items.add($item)
}
$form.controls.add($dropdown)
$dropdownlabel = new-object system.windows.forms.label
$dropdownlabel.location = new-object system.drawing.size(10,10)
$dropdownlabel.size = new-object system.drawing.size(100,20)
$dropdownlabel.text = "site code"
$form.controls.add($dropdownlabel)
$button = new-object system.windows.forms.button
$button.location = new-object system.drawing.size(100,50)
$button.size = new-object system.drawing.size(100,20)
$button.text = "select item"
$button.add_click({return-dropdown})
$form.controls.add($button)
$form.add_shown({$form.activate()})
$form.showdialog()
# set vairables mbx stores , oac stores #
if ($choice = "dal") {set-variable -name mbxdatabase -value mbstore01}
if ($choice = "dal") {set-variable -name oacdatabase -value oastore01}
enable-mailbox -identity $identity -database $mbxdatabase
enable-mailbox -identity $identity -archive -archivedatabase $oacdatabase
---end script---
-dempc
$csv = import-csv data.csv function return-dropdown { $choice = $dropdown.selecteditem.tostring() $form.close() $params = $csv | {$_.site -eq $choice} | foreach { new-object psobject @{ identity = $textbox1.text datastore = $_.datastore archive = $_.archive } } enable-mailbox @params } [void][system.reflection.assembly]::loadwithpartialname("system.windows.forms") [void][system.reflection.assembly]::loadwithpartialname("system.drawing") $button1 = new-object system.windows.forms.button $label1 = new-object system.windows.forms.label $label2 = new-object system.windows.forms.label $textbox1 = new-object system.windows.forms.textbox $combobox1 = new-object system.windows.forms.combobox $form = new-object system.windows.forms.form $button1.location = new-object system.drawing.point(124, 100) $button1.size = new-object system.drawing.size(107, 23) $button1.text = "enable" $button1.add_click({ if ($textbox1.text) { return-dropdown } else {[system.windows.forms.messagebox]::show("enter username!")} }) $label1.location = new-object system.drawing.point(15, 18) $label1.size = new-object system.drawing.size(60, 20) $label1.text = "username" $label2.location = new-object system.drawing.point(15, 67) $label2.size = new-object system.drawing.size(60, 15) $label2.text = "site code" $textbox1.location = new-object system.drawing.point(96, 18) $textbox1.name = "textbox1" $textbox1.size = new-object system.drawing.size(184, 20) $combobox1.location = new-object system.drawing.point(96, 59) $combobox1.size = new-object system.drawing.size(184, 21) foreach ($item in $csv) { [void]$combobox1.items.add($item.site) } $form.autoscaledimensions = new-object system.drawing.sizef(0x6f, 0x13f) $form.autoscalemode = [system.windows.forms.autoscalemode]::font $form.clientsize = new-object system.drawing.size(344, 140) $form.controls.add($combobox1) $form.controls.add($textbox1) $form.controls.add($label2) $form.controls.add($label1) $form.controls.add($button1) $form.text = "enable-mailbox" $form.add_shown({$form.activate()}) $form.showdialog()
Windows Server > Windows PowerShell
Comments
Post a Comment