Solved

Move Users Favorites Folder and then Delete?

Posted on 2014-03-03
7
386 Views
Last Modified: 2014-03-05
Hello,

My current scenario is as follows for user accounts:
\\90.244.233.10\userprofile$\User-16 (this is their profile path)
\\90.244.233.10\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:

\\90.244.233.10\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.
0
Comment
Question by:levertm
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 39901194
if (Test-Path -Path "\\90.244.233.10\userprofile$\User-16\Favorites") 
{
move-item -path  \\90.244.233.10\userprofile$\User-16\Favorites -destination \\90.244.233.10\userhome$\%username%\
remove-item -path  \\90.244.233.10\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
Move-item

Then delete the userprofile folder
Remove-Item
0
 

Author Comment

by:levertm
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)
0
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 39901249
gc users.txt | % {
$user = "$_"
if (Test-Path -Path "\\90.244.233.10\userprofile$\$user\Favorites") 
{
move-item -path  \\90.244.233.10\userprofile$\$user\Favorites -destination \\90.244.233.10\userhome$\$user\
remove-item -path  \\90.244.233.10\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)
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:levertm
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.
0
 

Author Comment

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

Expert Comment

by:becraig
ID: 39901382
ok sounds good.

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

Author Comment

by:levertm
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 :)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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