Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Newbie Needs Help With Folder script!

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 04-11-2007   #1 (permalink)
Mícheál
Guest


 

Newbie Needs Help With Folder script!

Hi All,

I need to write a script that reads in a list of user directories from
a text file, and renames any existing file to "usernameold", and then
just copies them from one share to another.

Basically I just want to rename \\oldserver\share\user1 to \\oldserver
\share\user1old and then to copy in \\newserver\share\user1 to \
\oldserver\share\user1. and to repeat this for a number of folders in
a text file.

Any hints, or starting points would be greatly appreciated!!

Cheers,
M


My System SpecsSystem Spec
Old 04-11-2007   #2 (permalink)
Nikhil R. Bhandari
Guest


 

Re: Newbie Needs Help With Folder script!

You can make use of following cmdlet + some logic for your requirement

#Check if the file exists or not
Test-Path $FileName

# Renames the file
Rename-Item -path $OldFileName $NewFileName

# Removes the file
Remove-Item $File

#Creates new directory
New-Item -Path $Folder -Name $FolderName -Type directory -Force


"Mícheál" <michael.halpin@gmail.com> wrote in message
news:1176290895.915025.187920@o5g2000hsb.googlegroups.com...
> Hi All,
>
> I need to write a script that reads in a list of user directories from
> a text file, and renames any existing file to "usernameold", and then
> just copies them from one share to another.
>
> Basically I just want to rename \\oldserver\share\user1 to \\oldserver
> \share\user1old and then to copy in \\newserver\share\user1 to \
> \oldserver\share\user1. and to repeat this for a number of folders in
> a text file.
>
> Any hints, or starting points would be greatly appreciated!!
>
> Cheers,
> M
>



My System SpecsSystem Spec
Old 04-11-2007   #3 (permalink)
Duncan Smith
Guest


 

Re: Newbie Needs Help With Folder script!

On Apr 11, 12:28 pm, "Mícheál" <michael.hal...@gmail.com> wrote:
> Hi All,
>
> I need to write a script that reads in a list of user directories from
> a text file, and renames any existing file to "usernameold", and then
> just copies them from one share to another.
>
> Basically I just want to rename \\oldserver\share\user1 to \\oldserver
> \share\user1old and then to copy in \\newserver\share\user1 to \
> \oldserver\share\user1. and to repeat this for a number of folders in
> a text file.
>
> Any hints, or starting points would be greatly appreciated!!
>
> Cheers,
> M


You could start by reading in the dir list and looping through each
line, and then inside that loop, loop through each of files contained
in each folder - something like this: untested - but should get you
going... ($_ refers to the current item in the iteration)

get-content dirlist.txt | foreach {
gci $_ | foreach {
cp $_.fullname "\\newserver\share\($_.name).old"
}
}

My System SpecsSystem Spec
Old 04-11-2007   #4 (permalink)
Mícheál
Guest


 

Re: Newbie Needs Help With Folder script!

On Apr 11, 1:43 pm, "Duncan Smith" <DSmith1...@googlemail.com> wrote:
> On Apr 11, 12:28 pm, "Mícheál" <michael.hal...@gmail.com> wrote:
>
> > Hi All,

>
> > I need to write a script that reads in a list of user directories from
> > a text file, and renames any existing file to "usernameold", and then
> > just copies them from one share to another.

>
> > Basically I just want to rename \\oldserver\share\user1 to \\oldserver
> > \share\user1old and then to copy in \\newserver\share\user1 to \
> > \oldserver\share\user1. and to repeat this for a number of folders in
> > a text file.

>
> > Any hints, or starting points would be greatly appreciated!!

>
> > Cheers,
> > M

>
> You could start by reading in the dir list and looping through each
> line, and then inside that loop, loop through each of files contained
> in each folder - something like this: untested - but should get you
> going... ($_ refers to the current item in the iteration)
>
> get-content dirlist.txt | foreach {
> gci $_ | foreach {
> cp $_.fullname "\\newserver\share\($_.name).old"
> }
>
> }


Thanks Duncan (and Nikhil),

I'l work from that and post back what I come up with.

Cheers!!
M

My System SpecsSystem Spec
Old 04-16-2007   #5 (permalink)
Mícheál
Guest


 

Re: Newbie Needs Help With Folder script!

On Apr 11, 2:01 pm, "Mícheál" <michael.hal...@gmail.com> wrote:
> On Apr 11, 1:43 pm, "Duncan Smith" <DSmith1...@googlemail.com> wrote:
>
>
>
> > On Apr 11, 12:28 pm, "Mícheál" <michael.hal...@gmail.com> wrote:

>
> > > Hi All,

>
> > > I need to write a script that reads in a list of user directories from
> > > a text file, and renames any existing file to "usernameold", and then
> > > just copies them from one share to another.

>
> > > Basically I just want to rename \\oldserver\share\user1 to \\oldserver
> > > \share\user1old and then to copy in \\newserver\share\user1 to \
> > > \oldserver\share\user1. and to repeat this for a number of folders in
> > > a text file.

>
> > > Any hints, or starting points would be greatly appreciated!!

>
> > > Cheers,
> > > M

>
> > You could start by reading in the dir list and looping through each
> > line, and then inside that loop, loop through each of files contained
> > in each folder - something like this: untested - but should get you
> > going... ($_ refers to the current item in the iteration)

>
> > get-content dirlist.txt | foreach {
> > gci $_ | foreach {
> > cp $_.fullname "\\newserver\share\($_.name).old"
> > }

>
> > }

>
> Thanks Duncan (and Nikhil),
>
> I'l work from that and post back what I come up with.
>
> Cheers!!
> M


Hi Guys,

in the end I didn't need to use it, but here's what I had and this bit
worked (mostly!). The mv command wouldn't work unless both shares had
the same root, I tried mapping drives to letters but still no joy.
Anyway, the little bit of code at the start might help someone!



$NewServer= "\\server2\test"
$OldServer= "\\server1\scripts"

gc c:\test\users.txt | Foreach-Object{
$folder = $_
echo "$folder" #just for debugging
ren $folder $folder+old
mv t:\$_ u:\
}

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: VB Script Code to get alert when a folder get changed in intranet FTP Folder nageswara Rao VB Script 0 05-20-2008 05:06 AM
<newbie> question regarding the AppData folder Jeff Vista General 2 02-13-2008 10:39 AM
Newbie question - Is there a script/command to do a backup of a di dob PowerShell 4 01-03-2008 09:45 AM
Newbie Question: Here-Script with PowerShell Raymund Hemmerling PowerShell 6 09-28-2007 03:34 AM
Newbie: running external script bill PowerShell 3 12-22-2006 03:09 AM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008