Solved

Powershell Script not executing as expected

Posted on 2011-02-14
1
404 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 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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 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 …

914 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now