Absolute Beginner

Welcome Forums General PowerShell Q&A Absolute Beginner

This topic contains 6 replies, has 3 voices, and was last updated by

1 year, 5 months ago.

  • Author
  • #80888

    Points: 0
    Rank: Member

    I have an application that has a bat file which can be ran which exports the configuration of the application to a directory named conf-exported. When it is ran, it creates a subdirectory in conf-exported named with a date time stamp format. For example, YYYYMMDDHHMMSS. I can automated the batch file to run daily in order to have the application configuration backed up daily. What I would like to do is move the subdirectory to another server. A copy is not good because the configuration contains encrypted credentials which may not work if I try to use the configuration on another server.

    Is there a simple way to do this in Powershell and create and update a log each time the subdirectory has been moved. Please advise. Thank you.

  • #80978

    Points: 67
    Rank: Member

    Move-Item is the cmdlet you want to use.

    • #80989

      Points: 0
      Rank: Member

      I think I may be able to use ROBOCOPY instead. I will test and see. Thanks.

  • #81085

    Points: 0
    Rank: Member

    Well, you indeed should use RoboCopy for this but not because that's easier and you are a beginner at Powershell.
    It's just the right tool for the job. You could create a BAT file with something that looks like this:

    set tdate=%date: =%
    set tdate=%tdate:/=%
    set ttime=%time::=%
    set ttime=%ttime:.=%
    set ttime=%ttime: =%
    echo off
    Robocopy \\ServerA\Folder1 \\ServerB\Folder1 /COPYALL /MOVE /R:2 /W:1 /log:c:\robocopy\AT_%tdate%-%ttime%_transferFiles.txt /v /tee /fp /eta

    So this way, each job would have a unique filename that has the date on which it was executed.
    You can lookup the parameters yourself (https://technet.microsoft.com/en-us/library/cc733145(v=ws.11).aspx),
    these are the ones i use mostly. It adds some visibility when you run them manually. In the scope of the script, some aren't as useful since you won't ever look at it.

    For reference:

    Moves files, and deletes them from the source after they are copied.
    Moves files and directories, and deletes them from the source after they are copied.

The topic ‘Absolute Beginner’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort