Mail-enable AD users using an interactive menu in Powershell
Hi
Please help with the following code.
Am making an interactive console to accept user input and mail-enable existing AD objects. Need to capture the UPN, email address and mailbox quota slab information from the heldpesk staff, and then create the mailbox.
$Quota1_l = 80MB
$Quota1_h = 100MB
$Quota2_l = 180MB
$Quota2_h = 200MB
$Quota3_l = 280MB
$Quota3_h = 300MB
Write-Host `n
$EmpNum = Read-Host "Enter Employee Number"
$EmailInput = Read-Host "Enter email Address"
#validate input email address
function ValidateEmail{
param([string]$EmailInput)
($EmailInput -as [System.Net.Mail.MailAddress]).Address `
-eq $EmailInput -and $EmailInput -ne $null
}
$result1 = ValidateEmail($EmailInput)
# this code needs to be corrected
while ($result1 -ne $True) { Write-Host "Email Address is invalid!" `n $EmailInput2 = Read-Host "Enter email Address"; $result1 = validateEmail($EmailInput2); break}
#end-correction
Write-Host "`nMailbox Quota: `n`n[1] Regular User: 100MB`n[2] Critical User: 200MB`n[3] Management User: 300MB" -foregroundcolor "white"
#Set Mailbox Quota Variables
$QuotaInput = Read-Host "`nEnter your choice"
if ($QuotaInput -eq 1) { $TempQuota_l = $Quota1_l; $TempQuota_h = $Quota1_h}
elseif ($QuotaInput -eq 2) { $TempQuota_l = $Quota2_l; $TempQuota_h = $Quota2_h}
elseif ($QuotaInput -eq 3) { $TempQuota_l = $Quota3_l; $TempQuota_h = $Quota3_h}
else { Write-Host "Incorrect Choice Entered"; break }
$EmpName = (Get-User -Identity $EmpNum).Name
$EmpTitle = (Get-User -Identity $EmpNum).Title
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes",""
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No",""
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)
Write-Host "`nMailbox will be created as:"
Write-Host "`nEmployee Name: $EmpName`nTitle: $EmpTitle`nEmployee Number: $EmpNum`nEmail Address: $EmailInput`nMailbox Quota Choice: $QuotaInput"
$message2 = "`nDo you want to proceed"
$result3 = $Host.UI.PromptForChoice($caption,$message2,$choices,0)
if($result3 -eq 0) {
#create mailbox script here - code not complete deliberately
Write-Host "`nMailbox Created Successfully! `n"
}
if($result3 -eq 1) {
Write-Host `n"No Action Taken!" `n
}
June 27th, 2011 11:17am
Hi
You can copy this thread to
development forum.Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
June 28th, 2011 8:47am