(Another) Recursive PowerShell Copy/Paste Folder Issue. PowerShell App Deployment Toolkit and SCCM

0

feel like I am going to laugh/Cry because I know that I am doing something stupid/obviously incorrect.

I am using SCCM and PSADT to attempt the below. It works fine if I UNC to the target folder and run the script but the below happens when deployed in SCCM

I have tried every variation of the below that I can think of. I am trying to move a directory from a networked VM to a local client but all I can seem to do is copy the EMPTY directory itself

examples of what I have tried are

If (!(Test-Path("C:\Target\"))) {
            New-Item -ItemType directory -Path "C:\Target"
            Copy-Item -Path "$dirFiles\Target\*" -Destination "C:\Target\" -Recurse -Force -Verbose
            } 

AND

  If (!(Test-Path("C:\Target\"))) {               
                Copy-Item -Path "$dirFiles\Target" -Destination "C:\" -Recurse -Force -Verbose
                } 

And everything in between I can think of. Each time I just get the empty directory folder created but none of the contents

user001

Posted 2018-03-09T09:23:40.643

Reputation: 101

I brought the target up a level to "$dirTarget" and it worked. Is SCCM unable to go 2 levels down or should I always have had the script like that? – user001 – 2018-03-09T10:11:37.800

It's unclear what you're attempting "I am using SCCM and PSADT to attempt the below." and what your current code looks like. Currently your variable $dirFiles is undefined. – Seth – 2018-03-09T10:16:01.357

It's part of a much larger toolkit which calls correctly for every other app. it defines the variables correctly (allowing me to access when running locally and on all other deployed Apps). I can see the folder being created in the destination directory but it is empty, the recursion is not taking – user001 – 2018-03-09T10:21:44.790

Answers

0

Sounds like a permissions issue. As you're running from SCCM, I would guess that you're using the pre-release Run Script feature. This runs the script as the computer's Local System account, which likely doesn't have the correct NTFS permissions to your network share.

If you're on a domain: As a quick, (dirty&insecure - revert this change immediately after testing!) test. Give Domain Computers read access to the $dirFiles\target folder and all child objects. If it works, you need to figure either:

  • How you want to structure access permissions for Local System accounts
  • Whether to turn script into a package or application and run as the logged in user instead.

The package option is safer, but a bit more long-winded.

Good luck

Pres

Posted 2018-03-09T09:23:40.643

Reputation: 68