SVN (Tortoise ) update using powershell

I am very new to PowerShell and Tortoise SVN both , and need to accomplish the following via PowerShell.

I am working off a Windows 2008 server that has Tortoise SVN installed.  
•      The SVN repository has been checked out locally to a c:\alpha\testops.
•      I have a local folder on the server “C:\beta\cons “which has a lot of subfolders and each subfolder has a few config files
•      This entire “cons” folder from the local server needs to be checked into SVN under the “testops\cons” folder.
•      The “CONS” folder already exists in the repository: Eg : c:\alpha\testops\cons)

The local folder where I have all the config files looks something like this:
C:\beta\cons \app1\config1.txt
C:\beta\cons \ app1\config2.txt

C:\beta\cons \ app2\config1.txt
C:\beta\cons \ app2\config2.txt

C:\beta\cons\ app3\config1.txt
C:\beta\cons\ app3\config2.txt

C:\beta\cons\app4\config1.txt
C:\beta\cons\ app4\config2.txt
etc

When checked into SVN, it should look something like this:
C:\alpha\testops\cons\
                                         \app1\
                                              config1.txt
                                              config2.txt
                                            \app2\
                                                      config1.txt
                                               config2.txt
                                               \app3\
                                                   Config1.txt
                                                 Config2.txt
Etc…

So the SVN steps that need to be accomplished via powershell   are:
1.      Run an update first to get the latest version of the repository.
2.      Add the  sub folders under  from c:\beta\cons\ (source folder )  to  c:\alpha\testops\cons\ (repository)
3.      Commit
4.      Update

Would very much appreciate your help .

 Thanks much ..
jpsainiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rushtoshankarSr Manager Software DevelopmentCommented:
Do you really need to use power shell to so svn operations? ( as you already have tortoise SVN?

Tortoise SVN is very easy to use interface. So I recommend you to use this to achieve your task.

First make sure that you dont have any files that are not in repository. You can check this by right clicking on "c:\alpha\testops\cons" folder and select TortoiseSVN->Add menu (If it is repository you should see an add menu). Now a new window will popup. If you see nothing in the new window, it is okay, skip the first step. If you see any files listed there in the new window, start from step 1.

1. check out the repository or cons folder in a fresh location
2. Use windows explorer to copy the files from source (c:\beta\cons) to destionation (c:\alpha\testops\cons)
3. Right click on the "cons" from the repository folder, select TortoiseSVN->Add menu.
A new window will popup with all the files and folder that you copied now. Click Ok.
4. Right click "cons" folder and select TortoiseSVN->Commit. Enter the description of the newly added files in the comment section
5. Right click->tortoiseSVN->update.

Now you have the latest repository with your files.

Feel free to ask if you need steps with powershell
0
jpsainiAuthor Commented:
Hi RushtoSankar,

Thanks for your response. Yes you are right .  Tortoise SVN is an easy to use interface and I have tested the above steps and it works fine.
However the direction within the team is " scripting and automation" and we have been asked to script pretty much everything via powershell and hence the reason for my post.  

Would really appreciate help with getting this scripted in powershell..
 

Thanks
0
rushtoshankarSr Manager Software DevelopmentCommented:
You have provided the list of steps that needs to be followed in a script.
Do you want the script to copy the files every time when it runs?
Do you have new folders/files under "c:\beta\cons" when the script runs every time? or Do you want the different folder folder to be copied every time?

Please explain me the steps other than last two lines - update/commit.
Like, coping the file from folders / get input from the user something like that.

if it has only simple steps, these can be achieved using simple dos batch files as well.
0
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

jpsainiAuthor Commented:
Hi

The c:\beta\cons folder could have new
        1. New folder and files every time the script runs
        2. Existing folders with updated config1.txt or config2.txt

I have a script which creates the  C:\beta\cons \app1 or C:\beta\cons\app2 etc folders and moves the respective config files to them.  
Once that script finishes, that is when I need this SVN  script to kick in :
Hope I answered your questions. Please let me know if you need any more information. I really appreciate your time and help.  

1. Checkout repository
2.Update
3. Add the folders\files  ( I thought copying the folders over to the local repository folder c:\alpha\testops\cons was enough. But the "Add" function still needs to be performed is what I realised).
4.commit
5. Update

I looked up   Tortoise SVN CLI   at http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-cli-main.html to get an understanding  of the commands

Thanks
0
rushtoshankarSr Manager Software DevelopmentCommented:
Copy the following lines to a batch file and try running it. It is simple easy to maintain batch file. It should work as you expected.

Make sure that svn.exe (svn client) is in PATH. If you need svn command line client you can use slik subversion as well.

@echo off
::save the current directory & change to repository folder
pushd C:\alpha\testops

:: update the working directory from SVN server/repository
svn update

::copying files from C:\Beta\cons to C:\alpha\testops\cons folder
xcopy C:\Beta\cons C:\alpha\testops\cons /E /F /Y

:: add the files that are newly copied
svn add --force

:: commit the newly added files with messsage
svn commit -m "Your log message goes here"

::restore (go back to) the original directory
popd
0
jpsainiAuthor Commented:
Hi ,

Thanks for the quick response with the dos batch file.  It definitely looks like it will do the job Unfortunately  the requirement is for a power shell script to do exactly the same.  It is a team wide initiate to use power shell only , coming from the top and hence the reason.

Could you please help with a power shell equivalent script as well?
I tried using something in the likes of below but it does not work.

Set-Alias tsvn 'C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe'
set-alias commit fn_commit
set-alias commit fn_update
function fn_commit($path = "C:\alpha\testops") {tsvn /command:commit /path:$path}
#function fn_update($path = "C:\alpha\testops") {tsvn /command:update /path:$path}

Then realized that I will have to use the svn cli commands like the one you have used in the DOS batch script, but just need it as a  power shell script.

Thanks again!  Much appreciated.
0
rushtoshankarSr Manager Software DevelopmentCommented:
Powershell can run most of the things that a normal cmd shell can run.

try copying the following lines in a powershell script (.ps1 extension) and run

#save the current directory & change to repository folder
#pushd may give errors if the destination is not present
pushd C:\alpha\testops

# update the working directory from SVN server/repository
svn update

#copying files from C:\Beta\cons to C:\alpha\testops\cons folder
xcopy C:\Beta\cons C:\alpha\testops\cons /E /F /Y

#add the files that are newly copied
svn add --force

#commit the newly added files with messsage
svn commit -m "Your log message goes here"

#restore (go back to) the original directory
popd

You can remove the push and pop commands if you dont need.
0
jpsainiAuthor Commented:
Thanks. Ok let me give it a try and will get back shortly.
0
jpsainiAuthor Commented:
Hi,

I was running the steps manually before running it via powershell and for
for svn add --force , it says
svn: E205001: Try 'svn help' for more info
svn: E205001: Not enough arguments provided

what could be causing it?

thanks!
0
rushtoshankarSr Manager Software DevelopmentCommented:
What version of SVN are you using?
0
jpsainiAuthor Commented:
Tortoise SVN 1.6.16, Build 21511 and the CLI is  CollabNetSubversion-client-1.7.4-1-x64 .
I was able to  svn add by specifying the folder like:

 >svn add cons\

Thought of giving the powershell script a shot and I  used these commands in a powershell script and ran it: But i get the below error:

The term 'svn' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
g of the name, or if a path was included, verify that the path is correct and try again.
At C:\test\asha\copytorepo_svn_v1.ps1:2 char:4
+ svn <<<<  update
    + CategoryInfo          : ObjectNotFound: (svn:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


This is the script. I substituted xcopy with Copy-Item cmdlet.

pushd C:\alpha\testops
svn update

# Set variables  here
$source = "c:\test\consumer\"
$destination = "C:\alpha\testops"
copy-item $source $destination -recurse
svn add consumer/
svn commit -m "Test checkin "
popd
0
jpsainiAuthor Commented:
In the path:

PATH=C:\Program Files\CollabNet\Subversion Client;C:\Windows\system32;C:\Windows
;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows
\idmu\common;C:\wintools;C:\Program Files\TortoiseSVN\bin
0
rushtoshankarSr Manager Software DevelopmentCommented:
Try changing "svn add --force" line to "svn add --force cons".

I missed the folder name to add.
0
jpsainiAuthor Commented:
ok  will try that..
but running it from powershell will still throw this error: thoughts>?


 Thought of giving the powershell script a shot and I  used these commands in a powershell script and ran it: But i get the below error:

The term 'svn' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
g of the name, or if a path was included, verify that the path is correct and try again.
At C:\test\asha\copytorepo_svn_v1.ps1:2 char:4
+ svn <<<<  update
    + CategoryInfo          : ObjectNotFound: (svn:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
jpsainiAuthor Commented:
Hi Rushtosankar,

i was able to accomplish what I was looking for. Your replies helped me get direction to the problem and I could  work off it.

Thanks!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jpsainiAuthor Commented:
i was able to accomplish what I was looking for. Your replies helped me get direction to the problem and I could  work off it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.