PowerShell Script to Mapped Drive

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

PowerShell Script to Mapped Drive

Post by jstevens »

I'm having a challenge with this bit of code: $files = Get-ChildItem -Path 'S:\myFiles' -Include.

PowerShell errors and tells me that there is no S drive. The drive letter is mapped properly. If I change the path to "C:\myFiles' the code processes correctly.

Your suggestions are appreciate.
Regards,
John

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: PowerShell Script to Mapped Drive

Post by jstevens »

Apparently running PowerShell as an Administrator doesn't allow one to access mapped drives due to permissions.
Regards,
John

JoeP
SilverLounger
Posts: 2069
Joined: 25 Jan 2010, 02:12

Re: PowerShell Script to Mapped Drive

Post by JoeP »

Mapped drives are per user so normally you need to be in the userid for the mapped drive to see them. To change this see Enable mapped drives in an elevated command prompt. The tutorial says for Windows 10 so may not work with Windows 11.
Joe

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: PowerShell Script to Mapped Drive

Post by jstevens »

Thanks Joe!
Regards,
John