locked
Batch moving files from no Windows server RRS feed

  • Question

  • Hi everybody,

    I wrote the following script to move all pdf files from a remote folder to a local one in batch

    It works if I run the script interactively but not in the scheduled job.

    Get-ChildItem -Path $remoteDir -filter "*.pdf"| % { 

    $pdftoMove=$_ 

    Move-Item -force $remoteDir\$pdftoMove $maindir 

    }

    Any suggest?

    Thanks!

    Paolo

    Thursday, November 23, 2017 10:04 AM

Answers

  • The pipeline does this without all of the excess bits:

    Get-ChildItem -Path $remoteDir -filter *.pdf | Move-Item -Destination $maindir -Force


    \_(ツ)_/

    Thursday, November 23, 2017 11:22 AM

All replies

  • Hello ,

    This should work .

    $source='c:\1\*.pdf'
    $des='c:\2\'
    get-childitem  $source -recurse | foreach-object {move-item $_ -destination $des }


    Thursday, November 23, 2017 10:27 AM
  • The pipeline does this without all of the excess bits:

    Get-ChildItem -Path $remoteDir -filter *.pdf | Move-Item -Destination $maindir -Force


    \_(ツ)_/

    Thursday, November 23, 2017 11:22 AM
  • thats' right! I did it. My problem was in the network mapping but using this code I solved

    $netdrive = New-Object -comobject Wscript.Network
    $netdrive.MapNetworkDrive("X:","\\mypath",0,"remoteserver\user","password")

    thanks!

    Friday, November 24, 2017 7:10 PM
  • If you just run the task under the required account you will not have to save a password in plain text in the script.  That is a very bad practice.


    \_(ツ)_/

    Friday, November 24, 2017 7:47 PM