Thread Closed 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error trying to reset AD password in Powershell (SOLVED)
17-05-2010, 12:58 PM
Post: #1
Error trying to reset AD password in Powershell (SOLVED)
I am trying to write an all singing and dancing script in power shell at the moment to process leavers, ie disable the user, change the OU to leavers, remove group memberships, set mail forwarding. The problem I am getting is I need to reset the users password in order to set their Out Of Office as only the mailbox owner has permissions to do this.

The relevant code from the script I am writing to this issue is
Code:
#Get full name of user to work with
$cname = Read-Host "Enter Full Name of Leaver"
#Create ADSI Connection
$userAD = [ADSI]"LDAP://CN=$cname,OU=Users,OU=London,DC=MYDOMAIN,DC=MYTLD"
#Reset Users Password to Printer123
$userAD.Invoke("setpassword","Printer123")
Now if I run this code from my desktop it runs fine but If I run it from the exchange server I get the following error
Quote:Exception calling "Invoke" with "2" argument(s): "Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERN
OTFOUND))"
At line:1 char:15
I have to run this script from the exchange server for the OOF setting script to work so really need to get this going.

Anyone got any ideas Huh

Follow me on Twitter
My Blog
Follow me on mFlow
Gamertag - Davotronic 5000
Send this user an email Visit this user's website Find all posts by this user
17-05-2010, 01:06 PM
Post: #2
Error trying to reset AD password in Powershell (SOLVED)
Does the "Password123" meet the password requirements of your domain policy?

- Techmonkey
================
Enterprise Business IT Support | SME IT Support | Home Support Available
Send this user an email Visit this user's website Find all posts by this user
17-05-2010, 01:15 PM
Post: #3
Error trying to reset AD password in Powershell (SOLVED)
It does when an administrator is setting a password not for a user choosing their own password. This script does work correctly when I run it from my desktop just not when run from the server, I have tried running the power shell as administrator as it is on Server 2008 R2 but still get the same error

Just in case I have tried the same script with a more secure password but get the same error.

Follow me on Twitter
My Blog
Follow me on mFlow
Gamertag - Davotronic 5000
Send this user an email Visit this user's website Find all posts by this user
17-05-2010, 02:01 PM
Post: #4
Error trying to reset AD password in Powershell (SOLVED)
Just to check, even though you are logged in as admin, try right click and Run As Administrator on your powershell, see if that helps

- Techmonkey
================
Enterprise Business IT Support | SME IT Support | Home Support Available
Send this user an email Visit this user's website Find all posts by this user
17-05-2010, 02:03 PM
Post: #5
Error trying to reset AD password in Powershell (SOLVED)
That is my most common mistake when using the more modern windows OS unfortunately not the solution today. Get the same error even when using the Run as Admin option

Follow me on Twitter
My Blog
Follow me on mFlow
Gamertag - Davotronic 5000
Send this user an email Visit this user's website Find all posts by this user
27-05-2010, 01:43 PM (This post was last modified: 27-05-2010 01:45 PM by Fail Whale.)
Post: #6
Error trying to reset AD password in Powershell (SOLVED)
I have made some changes to the script to eliminate potential problems so it now creates a random 10 character alphanumeric string with special characters and sets that as the password to make sure it reaches the complexity values.
Code:
#Get full name of user to work with
$cname = Read-Host "Enter Full Name of Leaver"

#Create ADSI Connection
$userAD = [ADSI]"LDAP://CN=$cname,OU=Users,OU=London,DC=MY DOMAIN, DC=MY TLD"

#Reset Users Password to random password
#Create variable with a random password
#Set up random number generator
$rand = New-Object System.Random
#Make sure the $NewPassword variable is empty
$NewPassword = ""
#Generate a new 10 character password
1..10 | ForEach { $NewPassword = $NewPassword + [char]$rand.next(33,127) }
#Reset Users password to randomly generated one
$userAD.Invoke("setpassword",$NewPassword)

but still get the same error if I run it on the server instead of my desktop. Does anyone know of any settings on the server which could cause this I have checked all the correct PSSnapins are present so am a bit stumped by this now.

Follow me on Twitter
My Blog
Follow me on mFlow
Gamertag - Davotronic 5000
Send this user an email Visit this user's website Find all posts by this user
03-06-2010, 02:04 PM
Post: #7
Error trying to reset AD password in Powershell (SOLVED)
couldn't get this working but did manage to get the OOF setting function to work on the local desktop instead.

Follow me on Twitter
My Blog
Follow me on mFlow
Gamertag - Davotronic 5000
Send this user an email Visit this user's website Find all posts by this user
03-06-2010, 11:16 PM
Post: #8
RE: Error trying to reset AD password in Powershell (SOLVED)
Sorry dude I kinda lost track of this one. Unfortunately have to go send a long email to a friend now on "how to make a website" lol.

Guess my answer must be slowly if this site is anything to go by.

- Techmonkey
================
Enterprise Business IT Support | SME IT Support | Home Support Available
Send this user an email Visit this user's website Find all posts by this user
Thread Closed 


Forum Jump: