Need help on powershell homefolder/localpath and UO change script

Welcome Forums General PowerShell Q&A Need help on powershell homefolder/localpath and UO change script

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
1 year, 8 months ago.

  • Author
    Posts
  • #66433

    Participant
    Points: 0
    Rank: Member

    Hi,

    I need som ehelp in creating 2 powershell script or 1 script with both changes coded.

    I need a script that changes home folder and local path on a list of AD usernames,
    from a file usernames.txt, where they are stored seperated by comma's.

    I also need a script, which when run moved the usernames from the txt file, from one OU to another OU.
    (From a OU with folder redirection enabled to a OU with redirection disabled)

    I have made a mockup of what i need the script to do with the folder issue,
    because it would be easier for me to explain this way.

    Please see the mockup here: https://www.dropbox.com/s/i12tipngi78rap6/Change_Needed_Home_folder.jpg?dl=0
    and then the script with the OU move from the same usernams.txt file.

    I am willing to pay a charge for help on these scripts, so i hope you/someone can help me on this.?

    Best regards

    Best regards

  • #66439

    Participant
    Points: 1
    Rank: Member

    Hi Brian,

    To continue where we left of.

    A payment is not needed. If I can help you we can all benefit for the knowledge of everyone. That's also the power in Powershell.

    For your first quest I have tested this script and it works like a charm. If you want, you can test it with a short list of test users if you want to.

    # First, change the usernames.txt to one username per line
    
    # If there is a wrong username in the list, continue with the next one.
    $ErrorActionPreference = 'SilentlyContinue'
    
    #get the usernames from the file and store them in the $users variable
    $users = Get-Content -Path 'C:\temp\usernames.txt'
    
    #run the command for each user in the variable.
    foreach ($user in $users)
    {
    	Set-ADUser -Identity $user -Clear homedirectory
    }
    
  • #66441

    Participant
    Points: 1
    Rank: Member

    .

  • #66444

    Participant
    Points: 1
    Rank: Member

    Basically you can use the same script to move the users. If you want you can combine the two in one script but to make it a bit more readable for you (to learn) I have put it in a separate script.

    Just adjust the line with $targetOU = 'OU=ouname,DC=company,DC=net' to something for the location the users must be in.

    # First, change the usernames.txt to one username per line
    
    #setting a variable for the OU
    $targetOU = 'OU=ouname,DC=company,DC=net'
    
    # If there is a wrong username in the list, continue with the next one.
    $ErrorActionPreference = 'SilentlyContinue'
    
    #get the usernames from the file and store them in the $users variable
    $users = Get-Content -Path 'C:\temp\usernames.txt'
    
    #run the command for each user in the variable.
    foreach ($user in $users)
    {
    	Get-ADUser -Identity $user | Move-ADObject -TargetPath $targetOU
    	
    }
     
    
  • #66451

    Participant
    Points: 0
    Rank: Member

    Hi Albert,
    Thank you so much,

    I will try to test the scripts on a testdomain and get back to you on this 🙂

    Best regards

The topic ‘Need help on powershell homefolder/localpath and UO change script’ is closed to new replies.