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.
If the service account doesn't have any access permissions at all on the
organizationfolder then that would be your issue.When connecting to that path, it has to first traverse through
organizationto reachdepartment1.So you (or your network team) have two options :
Grant the service user
This folder onlyread permissions to theorganizationfolder. That will allow it to navigate through there to the intended destination, but crucially by applying itThis folder onlyand not subfolders and files, it won't have access to the other files and subfolders, or for that matter be able to see them.Directly share the
department1folder, so you can simply connect straight to\\server1.com.au\department1\without needing to traverse theorganizationand therefore without needing any permissions to be applied to it.