none
ps1 file to rename and copy a folder RRS feed

  • General discussion

  • Hello,

    I am new to powershell.

    I am looking for a ps1 script that will rename the current folder (and overwrite if the folder exists) and copy the entire folder from a diff server.

    1. In Server B rename folder X to Y (if Y already exists then it shd overwrite it)

    2. Then copy folder X from server A to Server B

    Is this straight forward?

    Thanks

    Tuesday, March 29, 2016 7:52 PM

All replies

  • Sorry but we do not write scripts on demand.  You can use the resources here to write a script and ask questions about you script.

    You can start here: https://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx?f=255&MSPPError=-2147217396


    \_(ツ)_/

    Tuesday, March 29, 2016 7:57 PM
    Moderator
  • Is this straight forward?
    Yes. I suggest going through the link jrv posted to get your feet wet.

    Tuesday, March 29, 2016 8:16 PM
    Moderator
  • Here is my script:

    Remove-Item E:\Sage\MAS 90\Version45\MAS90\MAS_PHT_Old -recurse
    Rename-Item E:\Sage\MAS 90\Version45\MAS90\MAS_PHT MAS_PHT_Old
    Copy-Item \\pcs-mas-01\c$\Sage\Sage 100 Standard ERP\MAS90\MAS_PHT E:\Sage\MAS 90\Version45\MAS90 -recurse

    I saved it to a Mas90_refresh.ps1 file

    When executed I am getting the below errors:

    PS C:\Qlik_SLX> .\MAS90_Refresh.ps1
    Remove-Item : A positional parameter cannot be found that accepts argument '90\Version45\MAS90\MAS_PHT_Old'.
    At C:\Qlik_SLX\MAS90_Refresh.ps1:1 char:12
    + Remove-Item <<<<  E:\Sage\MAS 90\Version45\MAS90\MAS_PHT_Old -recurse
        + CategoryInfo          : InvalidArgument: (:) [Remove-Item], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

    Rename-Item : A positional parameter cannot be found that accepts argument 'MAS_PHT_Old'.
    At C:\Qlik_SLX\MAS90_Refresh.ps1:2 char:12
    + Rename-Item <<<<  E:\Sage\MAS 90\Version45\MAS90\MAS_PHT MAS_PHT_Old
        + CategoryInfo          : InvalidArgument: (:) [Rename-Item], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RenameItemCommand

    Copy-Item : A positional parameter cannot be found that accepts argument 'Standard'.
    At C:\Qlik_SLX\MAS90_Refresh.ps1:3 char:10
    + Copy-Item <<<<  \\pcs-mas-01\c$\Sage\Sage 100 Standard ERP\MAS90\MAS_PHT E:\Sage\MAS 90\Version45\MAS90 -recurse
        + CategoryInfo          : InvalidArgument: (:) [Copy-Item], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

    Friday, April 1, 2016 8:16 PM
  • When their are spaces in a path you need to use quotes.

    \_(ツ)_/

    Friday, April 1, 2016 9:13 PM
    Moderator
  • When their are spaces in a path you need to use quotes.

    \_(ツ)_/

    Great. I was able to get past that error but getting a new error. The path actually exist and my AD account is a member of domain admin group in Active Directory so I have permissions too. I am not sure if it needs to be shared. Here is the error:

    Copy-Item : Cannot find path '\\pcs-mas-01\c$\Sage\Sage 100 Standard ERP\MAS90\MAS_PHT' because it does not exist.
    At C:\Qlik_SLX\MAS90_Refresh.ps1:3 char:10
    + Copy-Item <<<<  "\\pcs-mas-01\c$\Sage\Sage 100 Standard ERP\MAS90\MAS_PHT" "E:\Sage\MAS 90\Version45\MAS90" -recurse
        + CategoryInfo          : ObjectNotFound: (\\pcs-mas-01\c$...P\MAS90\MAS_PHT:String) [Copy-Item], ItemNotFoundExce
       ption
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand


    Monday, April 4, 2016 6:46 PM