Import-Module ActiveDirectory
ForEach ($User in Import-Csv "c:\import.csv"){ #$user}
switch($user){
{$_.Version -eq "MSXC2010" -and $_.aktion -eq "new"} {
$user_dept = (Get-ADUser -identity $user.UserID).department
$user_db = (Get-Mailbox -Identity $user.userid).Database
if($user_db -notlike "*WEB*" -and $user_dept -like "EMC") {
$db = "DBEMC0$("{0:00}" -f (1..43 | Get-random))"
Enable-Mailbox -Identity $user.UserId $DB #here should enable all user in department EMC to Database DBEMC0 - DBEMC043
### Question No. 1 ####
}elseif ($user_db -like "*WEB*" | Out-File "c:\Temp\webUser.csv") { #here write userids database web to a file
### Question No. 2 ####
}elseif ($user_dep -notlike "*EMC*" -and $user_db -notlike "*WEB*") { # all user not department EMC and not Database WEB should be enable here
Enable-Mailbox -Identity $user.UserId
}
else {
$mbox = Get-Mailbox -Identity $User.userid
$mbox.EmailAddresses = $user.userid + "@emc.de"
$mbox.EmailAddresses+="MRS:$($user.userid)@MRS"
Set-Mailbox -Identity $User.userid -EmailAddresses $mbox.Emailaddresses -EmailAddressPolicyEnabled $False
switch($user.company){
"LCA*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'T' -CustomAttribute10 'LCA' -CustomAttribute14 'vcom'}
"LCG*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'K' -CustomAttribute10 'LCG' -CustomAttribute14 'vcom'}
"LCY*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LCY' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LCT*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LCT' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LCP*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LCP' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LTC*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LTC' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LVT*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LVT' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LCN*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LCN' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"BTL*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'BTL' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"BTM*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'BTM' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"BTS*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'BTS' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"DTN*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'DTN' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"KPA*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'KPA' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
default {Set-Mailbox -Identity $User.userid -CustomAttribute10 'EMC' -CustomAttribute4 'R' -CustomAttribute13 'vcom'}
}
$descnew = $user.orderid
$desccurrent = (Get-ADUser -identity $user.userid -Properties Description).Description
set-aduser -identity $user.userid -description ($desccurrent+"/"+$descnew+" ")
}
}
{$_.Version -eq "MSXC2010" -and $_.action -eq "delete"} {
$dbnew = (Get-Mailbox -Identity $user.userid | Select-Object Database)
$desccurrent = (Get-ADUser -identity $user.userid -Properties Description).Description
set-aduser -identity $user.userid -description ($desccurrent+"/"+$dbnew+" ")
#disable mailbox exchange 2010
Disable-Mailbox -Identity $user.UserID -confirm:$false
}
}
# If ($_.Version -eq "MSXC2010" -and $_.action -eq "New") {
{$_.Version -eq "MSXC2010" -and $_.aktion -eq "AdAccount"} {
$NewPassword = $user.UserId.Insert(5,"$")
$NewPassword = $newPassword.Insert(3,"L")
$NewPassword = $newPassword.Remove(0, 1)
$newPassword = $newPassword.Insert(0,"Z")
Set-ADAccountPassword -Identity $user.UserId -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $newPassword -Force)
write-host -ForegroundColor magenta "Password of $($user.UserId) has been set to $newPassword"
"User {0} Last PW Reset at {1}" -f $user.userid,((Get-ADUser $user.userid -properties PasswordLastSet).PasswordLastSet)
}
{$_.Version -eq "MSXC2010" -and $_.aktion -eq "New"} {
$PW = (Get-ADUser -identity $user.userid -properties * ).CannotChangePassword
If ($PW -eq $false) {
$GROUP = (Get-ADUser -identity $user.userid -Properties *).MemberOf | % { ($_ -split ",")[0] } | Where { $_ -like "CN=E*" }
If (!($GROUP)) {
$NewPassword = $user.userid.Insert(5,"$")
$NewPassword = $newPassword.Insert(3,"L")
$NewPassword = $newPassword.Remove(0, 1)
$newPassword = $newPassword.Insert(0,"Z")
Set-ADAccountPassword -Identity $user.userid -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $newPassword -Force)
write-host -ForegroundColor yellow "Password of $($user.UserId) has been set to $newPassword"
"User {0} Last PW Reset at {1}" -f $user.userid,((Get-ADUser $user.userid -properties PasswordLastSet).PasswordLastSet)
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE