r/PowerShell • u/thiagohds • Feb 11 '26
Solved PowerShell script not working with SMB directory
Hello, (code is here)
I have a NAS drive mounted and accessible on this windows machine and I want to move some files from one folder to another (within the NAS drive) but its not working. Ive tested with folders in my desktop directory and they work fine but when I try to use the SMB directory it doesnt work. I have read and write access to the drive.
The script gets the folder and list the subfolders but it seems to not find the items inside them. For what I've tested, the line that doesnt work is the following:
$docFiles = Get-ChildItem -Path $folderPath -File | Where-Object { $fileExtensions -contains $_.Extension }
For some reason, this is not getting the content of the folders. Ive tried the flag -Force but didnt work either.
I dont get any error in powershell. Any ideia whats going on?
3
u/Over_Dingo Feb 11 '26
does
Get-ChildItem -Path $folderPath -Filereturn anything?3
u/renevaessen Feb 11 '26
If your $folderPath does not contain wildcards, you could try -LiteralPath because maybe the path contains an invalid character like [ or ]
1
u/thiagohds Feb 11 '26
Update: I ended up moving the entire folder to a new location (a folder above where it was) and now the script is seeing the files. Maybe its something to do with the char length on windows cause the folder and files had a big name but i wasnt getting any error on the script.
1
u/OlivTheFrog Feb 11 '26
Hi u/thiagohds
When you use
Get-ChildItem, it stops at the first level unless you add the-Recurseparameter or the -Depth xx parameter to access sub-levelsRegards
1
u/meeu Feb 12 '26
Are you perhaps running powershell as administrator/elevated? SMB sign-ins are bound to the user session
1
u/stillnotlovin Feb 12 '26
correct
0
u/goldenfrogs17 Feb 11 '26
I have seen certain ISPs block this protocol.
0
u/[deleted] Feb 11 '26
Run in ISE one line at a time.
0
u/[deleted] Feb 11 '26
[deleted] — view deleted comment
1
u/[deleted] Feb 11 '26
[removed] — view removed comment