Move Users Favorites Folder and then Delete?

Posted on 2014-03-03
Medium Priority
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 2000 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)
Four New Appliances. Same Industry-leading Speeds.

But don't take it from us.  The Firebox M370 is Miercom tested and Miercom approved, outperforming its competitors for stateless and stateful traffic throughput scenarios.  Learn more about the M370, M470, M570 and M670 and find the right solution for your organization today!


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 http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28381231.html begraig if you're interested to take a stab :)

Featured Post

Bringing Advanced Authentication to the SMB Market

WatchGuard announces the acquisition of advanced authentication provider, Datablink, with one mission – to bring secure authentication to SMB, mid-market, and distributed enterprises with a cloud-based solution, ideal for resale via their established channel & MSSP community.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

800 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