?
Solved

Powershell Script not executing as expected

Posted on 2011-02-14
1
Medium Priority
?
418 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
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

850 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