Link to home
Start Free TrialLog in
Avatar of levertm
levertmFlag for Canada

asked on

Move Users Favorites Folder and then Delete?

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.
Avatar of becraig
becraig
Flag of United States of America image

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
Avatar of levertm

ASKER

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)
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of levertm

ASKER

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

Be back later with my findings and results.
Avatar of levertm

ASKER

Thank you becraig, that worked. Although I had to use the copy-item instead as the move-item gave me errors.
ok sounds good.

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

ASKER

I also posted this https://www.experts-exchange.com/questions/28381231/PowerShell-Set-Acl-recursively.html begraig if you're interested to take a stab :)