Cannot add “-persist” to New-PSDrive - getting error “network resource type is not correct”












1














As the title says, if I try to add -persist to the cmdlt, it returns an error:



New-PSDrive : The network resource type is not correct
At line:1 char:1
+ New-PSDrive -Name P -Root <redacted> ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
+ FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand



For reference, this is an administrator session in PowerShell, but I get the exact same responses if I do this in a regular user session:



PS> $PSVersionTable.psversion

Major Minor Build Revision
----- ----- ----- --------
5 1 16299 666


From the start: I validate that the drive letter I want to use is available (P, in this case)



PS> get-psdrive

Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
Alias Alias
C 36.80 22.11 FileSystem C: windowssystem32
Cert Certificate
D FileSystem D:
Env Environment
Function Function
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE ...ntrolNetworkProviderOrder
Variable Variable
WSMan WSMan


then I try to run: (I have already defined $locale as a variable as, e.g., '\foobar').



New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global

Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
P FileSystem \foobar


Happy days. That works. But of course, it's not visible to Windows Explorer, because it's just in this PS session. So, I destroy it (remove-psdrive P) and validate it's gone (get-psdrive), not shown here, then try to create a persistent version (same command, just with -persist):



PS> New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global -Persist
New-PSDrive : The network resource type is not correct
At line:1 char:1
+ New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope globa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
+ FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand


And it fails. For context, I'm doing this so I can script using RoboCopy with remote PSDrives (we want to use robocopy because of its built-in reporting, attribute management, and the ability to maintain file structure at the destination, and we want to use PSDrives so we can specificy credentials for the target drives).



Does anyone have any ideas?



Edit: Oh man... I can't believe this.... But just in case someone else finds this, I'm going to leave it. The problem was the trailing in my path. I removed that, and it persisted just fine.










share|improve this question





























    1














    As the title says, if I try to add -persist to the cmdlt, it returns an error:



    New-PSDrive : The network resource type is not correct
    At line:1 char:1
    + New-PSDrive -Name P -Root <redacted> ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
    + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand



    For reference, this is an administrator session in PowerShell, but I get the exact same responses if I do this in a regular user session:



    PS> $PSVersionTable.psversion

    Major Minor Build Revision
    ----- ----- ----- --------
    5 1 16299 666


    From the start: I validate that the drive letter I want to use is available (P, in this case)



    PS> get-psdrive

    Name Used (GB) Free (GB) Provider Root CurrentLocation
    ---- --------- --------- -------- ---- ---------------
    Alias Alias
    C 36.80 22.11 FileSystem C: windowssystem32
    Cert Certificate
    D FileSystem D:
    Env Environment
    Function Function
    HKCU Registry HKEY_CURRENT_USER
    HKLM Registry HKEY_LOCAL_MACHINE ...ntrolNetworkProviderOrder
    Variable Variable
    WSMan WSMan


    then I try to run: (I have already defined $locale as a variable as, e.g., '\foobar').



    New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global

    Name Used (GB) Free (GB) Provider Root CurrentLocation
    ---- --------- --------- -------- ---- ---------------
    P FileSystem \foobar


    Happy days. That works. But of course, it's not visible to Windows Explorer, because it's just in this PS session. So, I destroy it (remove-psdrive P) and validate it's gone (get-psdrive), not shown here, then try to create a persistent version (same command, just with -persist):



    PS> New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global -Persist
    New-PSDrive : The network resource type is not correct
    At line:1 char:1
    + New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope globa ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
    + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand


    And it fails. For context, I'm doing this so I can script using RoboCopy with remote PSDrives (we want to use robocopy because of its built-in reporting, attribute management, and the ability to maintain file structure at the destination, and we want to use PSDrives so we can specificy credentials for the target drives).



    Does anyone have any ideas?



    Edit: Oh man... I can't believe this.... But just in case someone else finds this, I'm going to leave it. The problem was the trailing in my path. I removed that, and it persisted just fine.










    share|improve this question



























      1












      1








      1


      2





      As the title says, if I try to add -persist to the cmdlt, it returns an error:



      New-PSDrive : The network resource type is not correct
      At line:1 char:1
      + New-PSDrive -Name P -Root <redacted> ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
      + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand



      For reference, this is an administrator session in PowerShell, but I get the exact same responses if I do this in a regular user session:



      PS> $PSVersionTable.psversion

      Major Minor Build Revision
      ----- ----- ----- --------
      5 1 16299 666


      From the start: I validate that the drive letter I want to use is available (P, in this case)



      PS> get-psdrive

      Name Used (GB) Free (GB) Provider Root CurrentLocation
      ---- --------- --------- -------- ---- ---------------
      Alias Alias
      C 36.80 22.11 FileSystem C: windowssystem32
      Cert Certificate
      D FileSystem D:
      Env Environment
      Function Function
      HKCU Registry HKEY_CURRENT_USER
      HKLM Registry HKEY_LOCAL_MACHINE ...ntrolNetworkProviderOrder
      Variable Variable
      WSMan WSMan


      then I try to run: (I have already defined $locale as a variable as, e.g., '\foobar').



      New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global

      Name Used (GB) Free (GB) Provider Root CurrentLocation
      ---- --------- --------- -------- ---- ---------------
      P FileSystem \foobar


      Happy days. That works. But of course, it's not visible to Windows Explorer, because it's just in this PS session. So, I destroy it (remove-psdrive P) and validate it's gone (get-psdrive), not shown here, then try to create a persistent version (same command, just with -persist):



      PS> New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global -Persist
      New-PSDrive : The network resource type is not correct
      At line:1 char:1
      + New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope globa ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
      + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand


      And it fails. For context, I'm doing this so I can script using RoboCopy with remote PSDrives (we want to use robocopy because of its built-in reporting, attribute management, and the ability to maintain file structure at the destination, and we want to use PSDrives so we can specificy credentials for the target drives).



      Does anyone have any ideas?



      Edit: Oh man... I can't believe this.... But just in case someone else finds this, I'm going to leave it. The problem was the trailing in my path. I removed that, and it persisted just fine.










      share|improve this question















      As the title says, if I try to add -persist to the cmdlt, it returns an error:



      New-PSDrive : The network resource type is not correct
      At line:1 char:1
      + New-PSDrive -Name P -Root <redacted> ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
      + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand



      For reference, this is an administrator session in PowerShell, but I get the exact same responses if I do this in a regular user session:



      PS> $PSVersionTable.psversion

      Major Minor Build Revision
      ----- ----- ----- --------
      5 1 16299 666


      From the start: I validate that the drive letter I want to use is available (P, in this case)



      PS> get-psdrive

      Name Used (GB) Free (GB) Provider Root CurrentLocation
      ---- --------- --------- -------- ---- ---------------
      Alias Alias
      C 36.80 22.11 FileSystem C: windowssystem32
      Cert Certificate
      D FileSystem D:
      Env Environment
      Function Function
      HKCU Registry HKEY_CURRENT_USER
      HKLM Registry HKEY_LOCAL_MACHINE ...ntrolNetworkProviderOrder
      Variable Variable
      WSMan WSMan


      then I try to run: (I have already defined $locale as a variable as, e.g., '\foobar').



      New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global

      Name Used (GB) Free (GB) Provider Root CurrentLocation
      ---- --------- --------- -------- ---- ---------------
      P FileSystem \foobar


      Happy days. That works. But of course, it's not visible to Windows Explorer, because it's just in this PS session. So, I destroy it (remove-psdrive P) and validate it's gone (get-psdrive), not shown here, then try to create a persistent version (same command, just with -persist):



      PS> New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global -Persist
      New-PSDrive : The network resource type is not correct
      At line:1 char:1
      + New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope globa ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
      + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand


      And it fails. For context, I'm doing this so I can script using RoboCopy with remote PSDrives (we want to use robocopy because of its built-in reporting, attribute management, and the ability to maintain file structure at the destination, and we want to use PSDrives so we can specificy credentials for the target drives).



      Does anyone have any ideas?



      Edit: Oh man... I can't believe this.... But just in case someone else finds this, I'm going to leave it. The problem was the trailing in my path. I removed that, and it persisted just fine.







      powershell windows-scripting drive-mapping powershell-v5.1 new-psdrive






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 at 13:39









      mklement0

      126k20239267




      126k20239267










      asked Nov 12 at 17:50









      RSchreib

      84




      84
























          1 Answer
          1






          active

          oldest

          votes


















          0














          As you've discovered:



          Don't specify drive root paths with a trailing , because doing so causes New-PSDrive to fail with obscure error message New-PSDrive : The network resource type is not correct when -Persist is used:



          # Trailing '': only OK *without* -Persist.
          New-PSDrive -root \foobar -name N -PSProvider filesystem

          # !! Breaks with -Persist:
          New-PSDrive -root \foobar -name N -PSProvider filesystem

          # No trailing '': OK both with and without -Persist
          New-PSDrive -root \foobar -name N -PSProvider filesystem


          I've reported this unexpected behavior on GitHub, and a fix has been green-lighted for PowerShell Core, though it's unclear in what future version it will be available (written as of PowerShell Core 6.2.0-preview.1).






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267525%2fcannot-add-persist-to-new-psdrive-getting-error-network-resource-type-is-n%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            As you've discovered:



            Don't specify drive root paths with a trailing , because doing so causes New-PSDrive to fail with obscure error message New-PSDrive : The network resource type is not correct when -Persist is used:



            # Trailing '': only OK *without* -Persist.
            New-PSDrive -root \foobar -name N -PSProvider filesystem

            # !! Breaks with -Persist:
            New-PSDrive -root \foobar -name N -PSProvider filesystem

            # No trailing '': OK both with and without -Persist
            New-PSDrive -root \foobar -name N -PSProvider filesystem


            I've reported this unexpected behavior on GitHub, and a fix has been green-lighted for PowerShell Core, though it's unclear in what future version it will be available (written as of PowerShell Core 6.2.0-preview.1).






            share|improve this answer




























              0














              As you've discovered:



              Don't specify drive root paths with a trailing , because doing so causes New-PSDrive to fail with obscure error message New-PSDrive : The network resource type is not correct when -Persist is used:



              # Trailing '': only OK *without* -Persist.
              New-PSDrive -root \foobar -name N -PSProvider filesystem

              # !! Breaks with -Persist:
              New-PSDrive -root \foobar -name N -PSProvider filesystem

              # No trailing '': OK both with and without -Persist
              New-PSDrive -root \foobar -name N -PSProvider filesystem


              I've reported this unexpected behavior on GitHub, and a fix has been green-lighted for PowerShell Core, though it's unclear in what future version it will be available (written as of PowerShell Core 6.2.0-preview.1).






              share|improve this answer


























                0












                0








                0






                As you've discovered:



                Don't specify drive root paths with a trailing , because doing so causes New-PSDrive to fail with obscure error message New-PSDrive : The network resource type is not correct when -Persist is used:



                # Trailing '': only OK *without* -Persist.
                New-PSDrive -root \foobar -name N -PSProvider filesystem

                # !! Breaks with -Persist:
                New-PSDrive -root \foobar -name N -PSProvider filesystem

                # No trailing '': OK both with and without -Persist
                New-PSDrive -root \foobar -name N -PSProvider filesystem


                I've reported this unexpected behavior on GitHub, and a fix has been green-lighted for PowerShell Core, though it's unclear in what future version it will be available (written as of PowerShell Core 6.2.0-preview.1).






                share|improve this answer














                As you've discovered:



                Don't specify drive root paths with a trailing , because doing so causes New-PSDrive to fail with obscure error message New-PSDrive : The network resource type is not correct when -Persist is used:



                # Trailing '': only OK *without* -Persist.
                New-PSDrive -root \foobar -name N -PSProvider filesystem

                # !! Breaks with -Persist:
                New-PSDrive -root \foobar -name N -PSProvider filesystem

                # No trailing '': OK both with and without -Persist
                New-PSDrive -root \foobar -name N -PSProvider filesystem


                I've reported this unexpected behavior on GitHub, and a fix has been green-lighted for PowerShell Core, though it's unclear in what future version it will be available (written as of PowerShell Core 6.2.0-preview.1).







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 13 at 19:02

























                answered Nov 12 at 20:46









                mklement0

                126k20239267




                126k20239267






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267525%2fcannot-add-persist-to-new-psdrive-getting-error-network-resource-type-is-n%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine