How can I fix my powershell script for NAS deployment on new PCs?


  1. Posts : 217
    Windows 10
       #1

    How can I fix my powershell script for NAS deployment on new PCs?


    Current script is:

    Code:
    cmdkey /add:(name of my NAS) /user:network\(username on NAS) /pass:(password for username on NAS)
    New-PSDrive -Name "E" -Root "\\(name of my NAS)\(name of shared folder)" -Persist -PSProvider "FileSystem"
    This will map one of the shared folders that the user has access to on the NAS as a local drive on the PC. Of course if there are more than 1 shared folders the user has access to on the NAS and wants them mapped, then the

    Code:
    New-PSDrive -Name "E" -Root "\\(name of my NAS)\(name of shared folder)" -Persist -PSProvider "FileSystem"
    part needs to be used/written again but now with a different letter than "E"

    This is pretty complicated even on just a select few PCs. I want to rewrite the script in a way that once the system knows the NAS user account (username + password), it will automatically map all the network folders they have access to as local drives on the PC.

    Any ideas how this could work? I know in AD you have a way to do this but none of my PCs are domain-joined and I don't have an AD domain.
      My Computer


  2. Posts : 1,097
    Windows 10
       #2

    Wouldn't you add a new entry for each key?

    So logic like this
    Code:
    cmdkey /add:nasDriveE New-PSDrive -Name "E"
    cmdkey /add:nasDriveB New-PSDrive -Name "B"
    etc?

    atm each time you are updating the one key but i think maybe it makes more sense to make keys for each shared folder, sorry idk exactly without having to try run through it myself but the logic makes sense to me.
      My Computer


  3. Posts : 217
    Windows 10
    Thread Starter
       #3

    Malneb said:
    Wouldn't you add a new entry for each key?

    So logic like this
    Code:
    cmdkey /add:nasDriveE New-PSDrive -Name "E"
    cmdkey /add:nasDriveB New-PSDrive -Name "B"
    etc?

    atm each time you are updating the one key but i think maybe it makes more sense to make keys for each shared folder, sorry idk exactly without having to try run through it myself but the logic makes sense to me.
    I am looking for a way to make the code make the NAS know what network shares are to be mapped as local drives depending on the specific NAS user account
      My Computer


  4. Posts : 1,097
    Windows 10
       #4

    Yeah so make a key for each drive/user per the example. When it needs to be a different user or drive then make a new key each time.

    Just think about what you are doing and what you are wanting to achieve so atm you are updating the one key which is your problem.
    separate keys for separate parameters is your answer again as per the example.

    Unless i am missing something but it seems like pretty simple logic to me.

    key 1: user123, parameters: abc
    key 2: user123, parameters: def

    key 3: userXYZ, parameters: abc
    key 4: userXYZ, parameters: def

    key5: userJKL0, parameters: def

    etc
      My Computer


  5. Posts : 217
    Windows 10
    Thread Starter
       #5

    Malneb said:
    Yeah so make a key for each drive/user per the example. When it needs to be a different user or drive then make a new key each time.

    Just think about what you are doing and what you are wanting to achieve so atm you are updating the one key which is your problem.
    separate keys for separate parameters is your answer again as per the example.

    Unless i am missing something but it seems like pretty simple logic to me.

    key 1: user123, parameters: abc
    key 2: user123, parameters: def

    key 3: userXYZ, parameters: abc
    key 4: userXYZ, parameters: def

    key5: userJKL0, parameters: def

    etc
    No. You misunderstood. I want the code to get the NAS to automatically know and map all the network shares the user has access to as local drives in My Computer. I don't want to have to do the mapping via code, I want it to be automatic.
      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 14:44.
Find Us




Windows 10 Forums