Link to home
Start Free TrialLog in
Avatar of Mandy_
Mandy_

asked on

Powershell Read used Exchange Databasename from AD and add to Description

hi,
with script below i like to create, delete or reset password of new exchange user
from a csv like below. My problem is i like to add the orderid and used database
to the description of user to delete
and only the orderID to user i create.
The database used i've to read from ad attribute. The description
i like to add to existing description.
See code in ####

ForEach ($User in  Import-Csv  "c:\import.csv") {    
    If($User.Version -like "M2010") {
        If($User.Action -like "new") {
             # activate Exchange 2010 Mailbox
             Enable-Mailbox -Identity $User.UserID -Database DB0001
        } # end if create
        If($User.action -like "delete") {
             # deactivate Exchange 2010 Mailbox
             Disable-Mailbox -Identity $User.UserID 
########################################
#$descnew = $entry.OrderID	
#$desccurrent = (Get-ADUser -identity $entry.userid -Properties Description).Description
#set-aduser -identity $user.userid -description ($desccurrent+' '+$descnew+' ')
#Read used database from AD
########################################

        } # end if delete
  If($User.Action -like "reset") {
       #If($User.Version -like "reset") {
       # reset password of AD-Account
Import-Module activedirectory
$NewPassword = $user.UserId.Insert(5,"$").Insert(3,"p").Remove(0, 1).Insert(0,"C")
write-host The new password is $newpassword
Set-ADAccountPassword -Identity $user.userid -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$newpassword" -Force)

Open in new window


CSV i'm using

UserId,OrderId,Action,Version
Z402594,151911,New,M2010   - only orderid to desc.
Z524027,151928,Delete,MSXC2010  - read DB and orderid to desc.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial