Asked by:
using set-aduser for logon script

General discussion
-
I am new to Powershell and have the following issue
I need to take the logon script from one user and put it to another user but I am having troubles.
Thanks in advance for any help
$UserName = Read-Host "Enter the users name" $NewUser = Read-Host "Enter the new users name" $Nuser = Get-ADuser -Filter {displayName -eq $NewUser} | Select-Object SamAccountName Get-ADUser -Filter {displayName -eq $UserName} -Properties ScriptPath | Set-Aduser $Nuser
- Edited by MrSmity101 Thursday, July 19, 2018 2:30 PM
- Changed type Bill_Stewart Tuesday, December 11, 2018 9:03 PM
- Moved by Bill_Stewart Tuesday, December 11, 2018 9:03 PM Unanswerable drive-by question
Thursday, July 19, 2018 2:30 PM
All replies
-
Do you mean set the script path. Logon scripts are set by Group Policy. Talk to your AD Administrator for assistance setting a users logon script.
\_(ツ)_/
Thursday, July 19, 2018 2:34 PM -
Do you mean you want to copy the scriptPath attribute from one AD user account to another?
Here's an example (not tested, but you get the idea):
$user1 = Get-ADUser "user1" -Properties scriptPath Get-ADuser "user2" | Set-ADUser -ScriptPath $user1.scriptPath
-- Bill Stewart [Bill_Stewart]
- Edited by Bill_Stewart Thursday, July 19, 2018 2:41 PM
Thursday, July 19, 2018 2:34 PM -
$scriptfromuser = get-aduser -identity $username -properties scriptpath | select -expandproperty scriptpath set-aduser -identity $newuser -scriptpath $scriptfromuser
Thursday, July 19, 2018 2:36 PM -
You don't say how the script fails, but your Set-ADUser cmdlet doesn't assign anything. As noted, use the -ScriptPath parameter. Also, the displayName attribute may not be assigned a value, or more than one user can have the same value. Are you sure the displayName uniquely identifies the users? Maybe you want Name, or better yet, sAMAccountName (pre-Windows 2000 logon name).
Richard Mueller - MVP Enterprise Mobility (Identity and Access)
Thursday, July 19, 2018 4:38 PM