Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Newbie Needs Help With Folder script!

Reply
 
Old 04-11-2007   #1 (permalink)
Mícheál


 
 

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


 
 

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


 
 

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


 
 

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


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Newbie using script but fails PowerShell
<newbie> question regarding the AppData folder Vista General
Newbie question - Is there a script/command to do a backup of a di PowerShell
Newbie Question: Here-Script with PowerShell PowerShell
Newbie: running external script PowerShell


Vista Forums 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 Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46