04/28/2015 6982 views

I need to copy files from a server\share to a local machine using robocopy or powershell. I can successfully run via a command prompt this command line: %windir%\system32\robocopy.exe \\GHJKL000\Temp\FileCopy\ScreenSaverFiles C:\Users\Public\Pictures *.* /S /E /COPYALL /R:1000000 /W:30. However, when I add this command line to a program and try run this via SCCM 2012, it doesn't copy. Do I need to add quotes?

Thx in advance

0 Comments   [ + ] Show comments


All Answers



For example: xcopy %~dp0*.* C:\Users\Public\Pictures\ /E /H /R /K /Y

good luck...

Answered 04/29/2015 by: ThebeMatshana
White Belt

How do you have the script set to run? If it's the default, it'll be running using the local System account which, as you know, has no network access. You'll need to set it to run in logged-in user Context.
Answered 04/29/2015 by: VBScab
Red Belt

Give this a go, i have just created it today for a task, it works in my test environment.
Put the code in a PS1 file and you should be good to go.

    $HostName = Servername'
    $Path = "Path on server to create folder"
    $TestPing = Test-Connection $HostName -count 1 -Quiet -ErrorAction SilentlyContinue #Checks to see if server is up
    $ValidPath = Test-path $Path #Validates path exisit
#If statement checks to see if path exist and server is up are both true, if the path exist all is good, if not it creates it.

    IF (($ValidPath -eq $True) -and ($testping -eq $True)){
        Write-Host 'Path Exist! - '$Path -ForegroundColor Green
        Write-Host 'Path Does Not Exist!' -ForegroundColor Yellow
        New-Item -ItemType Directory -Path $Path
        $ValidPath = Test-path $Path
        If ($ValidPath) {Write-Host 'Path has been created' -ForegroundColor Green}Else{'Path does not exist'}

    #Copy files to host, if path exist or once path has been created - take of -Confirm this will prompt for confirmation to run or you can use -Whatif to simulate if it will work otherwise delete to run in live mode
    Copy-Item -Path "Path of source files" -Destination $Path -Recurse -Force -Confirm
Answered 07/20/2015 by: Thegunner
Second Degree Green Belt