How to connect NAS to computer with powershell script?  


  1. Posts : 217
    Windows 10
       #1

    How to connect NAS to computer with powershell script?


    okay so for the past 1 hour I've been rewriting the same script over and over again to no avail. It still isn't working.
    I need the script coz I want to put it in the image I'm going to capture with NTLite

    I have a NAS called X. There's many user accounts for this NAS. There's also many network shares on this NAS (shared folders).
    I want the powershell script to first install the Windows Credential Manager module from the Powershell Repository. Once done, there will be a pop-up asking the user to enter their credentials for the NAS called X (\\X). Once the credentials have been entered and the user has logged into the NAS with their account, the shared folders that the user has access to will be mapped with a drive letter to their computer.

    I have been trying to get this script to work to no avail and I'm pulling my hair out over frustration. I've rewritten the same script over 50 times in the past 1 hour
      My Computer


  2. Posts : 13,752
    Win10 Version 22H2 Pro and Home, Win11 Pro and Home
       #2

    Don't know how it can be done in PS [still trying to learn PS] but when I want access to my NAS, connected via Ethernet to the Wireless Router, I have to assure the settings in this image are correct [Control Panel, Network and Sharing Center]. I have computers connected both Wired and Wireless/Wi-Fi and Map the Public folder on the NAS drive. And can do it from Win7, Win10 and Win11.

    How to connect NAS to computer with powershell script?-screenshot-2023-02-21-134552.png
      My Computers


  3. Posts : 5,048
    Windows 10/11 Pro x64, Various Linux Builds, Networking, Storage, Cybersecurity Specialty.
       #3

    Studynxx said:
    okay so for the past 1 hour I've been rewriting the same script over and over again to no avail. It still isn't working.
    I need the script coz I want to put it in the image I'm going to capture with NTLite

    I have a NAS called X. There's many user accounts for this NAS. There's also many network shares on this NAS (shared folders).
    I want the powershell script to first install the Windows Credential Manager module from the Powershell Repository. Once done, there will be a pop-up asking the user to enter their credentials for the NAS called X (\\X). Once the credentials have been entered and the user has logged into the NAS with their account, the shared folders that the user has access to will be mapped with a drive letter to their computer.

    I have been trying to get this script to work to no avail and I'm pulling my hair out over frustration. I've rewritten the same script over 50 times in the past 1 hour
    IDK -

    Maybe?

    How to map to a network drive using a Powershell script - Stack Overflow

      My Computer


  4. Posts : 217
    Windows 10
    Thread Starter
       #4

    Berton said:
    Don't know how it can be done in PS [still trying to learn PS] but when I want access to my NAS, connected via Ethernet to the Wireless Router, I have to assure the settings in this image are correct [Control Panel, Network and Sharing Center]. I have computers connected both Wired and Wireless/Wi-Fi and Map the Public folder on the NAS drive. And can do it from Win7, Win10 and Win11.

    How to connect NAS to computer with powershell script?-screenshot-2023-02-21-134552.png
    You misunderstood the question. That wasn't what I was asking.

    - - - Updated - - -

    I found a website with valuable info but I'm still struggling to understand why my script isn't working. Here's the script I've written:

    cmdkey /addcname /user:network\username /passassword

    This will create an entry in the Windows Credential Manager. So far so good.

    Now I add the 2nd part of the script:

    New-PSDrive -Name "E" (you can choose any drive letters you like) -Root "\\server\share" -Persist -PSProvider "FileSystem"

    So this will 'map' the drive in the powershell terminal, BUT when I go into File Explorer, the 'mapped' drive isn't there! It should look like this:

    How to connect NAS to computer with powershell script?-example.png

    But it never appears in File Explorer like this. This would be the whole point of mapping the network drive.

    - - - Updated - - -

    Update: OK, the problem was that I ran the script as admin in the PS-console. If I run it as standard user, the mapped drive appears in Windows File Explorer.

    However, there's a problem: I haven't found a way to generalize the script. It's too manual. It should prompt the user to log into the NAS with their account and once he's done it, the script will map all the network shares that the user (on the NAS) has access to.

    I've been trying to do this for a couple of hours since today and I still can't do it.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 06:52.
Find Us




Windows 10 Forums