Move Users Favorites Folder and then Delete?

Posted on 2014-03-03
Last Modified: 2014-03-05

My current scenario is as follows for user accounts:
\\\userprofile$\User-16 (this is their profile path)
\\\userprofile$\User-16\Favorites (this is their favorites folder)

I need to take the above favorites folder and move it to their userhome$ folder found here:

\\\userhome$\%username%\Favorites (these folders already exist)

Then delete their complete userprofile$ folder.

How can I achieve this using powershell? I think the tricky part for me is going through each folder in userprofile$ and looking for a \Favorites folder and then matching that userprofile$ foldername to %username% since they're the same.
Thank you.
Question by:levertm
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
  • 4
  • 3
LVL 29

Expert Comment

ID: 39901194
if (Test-Path -Path "\\\userprofile$\User-16\Favorites") 
move-item -path  \\\userprofile$\User-16\Favorites -destination \\\userhome$\%username%\
remove-item -path  \\\userprofile$\User-16 -recurse

Open in new window

Something like above should work, very simple.

The if statement verifies if the folder exists.

If it does you proceed to move the favorites folder

Then delete the userprofile folder

Author Comment

ID: 39901231
Hi becraig,

Thanks for the input, it's a good start. How do I go about talking over 100 user accounts? I would have to run this script with variable so as to not set any hard coded values for account usernames (ie: user-16)
LVL 29

Accepted Solution

becraig earned 500 total points
ID: 39901249
gc users.txt | % {
$user = "$_"
if (Test-Path -Path "\\\userprofile$\$user\Favorites") 
move-item -path  \\\userprofile$\$user\Favorites -destination \\\userhome$\$user\
remove-item -path  \\\userprofile$\$user -recurse

Open in new window

This is assuming you have a text file with the username one per line (Matching the exact folder names)
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Author Comment

ID: 39901256
I will generate a text file and test your code in my environment right now!

Be back later with my findings and results.

Author Comment

ID: 39901366
Thank you becraig, that worked. Although I had to use the copy-item instead as the move-item gave me errors.
LVL 29

Expert Comment

ID: 39901382
ok sounds good.

As a rule of thumb I always copy (just in case)

Author Comment

ID: 39907786
I also posted this begraig if you're interested to take a stab :)

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

695 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