?
Solved

Powershell Script not executing as expected

Posted on 2011-02-14
1
Medium Priority
?
413 Views
Last Modified: 2012-05-11
Experts,

      the code below is not executing as expected. I am getting an error "cmdlet set -qaduser at command pipeline position supply values for following parameters  Identity:

I expected the code to just go through and change the two users to the new password and write both password changes to the text file. I am only getting one user change being piped out to text file.

Please advise
Missymadi
$users = @(
"Reset1"
"Reset2"
) 
$users | %{
set-qaduser -Userpassword 'Test'
Write-host "$($_) password was reset"
get-qaduser -samaccountname $_.samaccountname | Select samaccountname, passwordlastset | out-file c:\ResetCrew.txt -noclobber
}

Open in new window

0
Comment
Question by:missymadi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 27

Accepted Solution

by:
KenMcF earned 2000 total points
ID: 34892346
Without testing it looks like you are missing one part, just add get-qaduser like below and test.

$users = @(  
"Reset1"  
"Reset2"  
)  
$users | %{  
get-qaduser -samaccountname $_ | set-qaduser -Userpassword 'Test'  
Write-host "$($_) password was reset"  
get-qaduser -samaccountname $_.samaccountname | Select samaccountname, passwordlastset | out-file c:\ResetCrew.txt -noclobber  
}
0

Featured Post

Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question