Read files from a subdirectory with different access permission from parent folder

45 Views Asked by At

I'm trying to create a tool to read folders and files from a NAS drive then compress and upload it to another NAS drive. My problem is that I've only been provisioned a read/write permission on the subdirectory but not the parent directory by the network team, given that different departments are using the same parent folder and that it contains other confidential files.

To demonstrate the problem, in the example NAS drive below I only have read/write access to "department1" folder but not in "organization":

\server1.com.au\organization\department1\users\user1

This is the code I'm using to read the folders and files that I need to compress, however, I'm getting "Access is denied" error.

$sourcePath = "\\server1.com.au\organization\department1\users\user1"
$files = Get-ChildItem -Path $sourcePath -Recurse -Force -ErrorAction SilentlyContinue -ErrorVariable errorFileList

I'm kinda stuck here, and I'm hoping someone could help me on this.

1

There are 1 best solutions below

0
Keith Langmead On

If the service account doesn't have any access permissions at all on the organization folder then that would be your issue.

When connecting to that path, it has to first traverse through organization to reach department1.

So you (or your network team) have two options :

  1. Grant the service user This folder only read permissions to the organization folder. That will allow it to navigate through there to the intended destination, but crucially by applying it This folder only and not subfolders and files, it won't have access to the other files and subfolders, or for that matter be able to see them.

  2. Directly share the department1 folder, so you can simply connect straight to \\server1.com.au\department1\ without needing to traverse the organization and therefore without needing any permissions to be applied to it.