locked
Mapping persistent drives with New-PSDrive using WINRM sessions RRS feed

  • Question

  • Hi All,

    I am trying to map persistent drives using New-PSDrive on a remote <g class="gr_ gr_21 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="21" id="21">winrm</g> session.

    The command works OK (the drive is mapped), but when I opened a new session the mapping driver got the status of "Unavailable". I am using CREDSSP

    Eg:

    #Session A creating the mapping

    $credentials = Get-Credential user
    $session = New-PSSession -ComputerName Server1 -Credential $credentials -Authentication CredSSP
    $computername = "Server2"
    Invoke-Command -Session $session -ScriptBlock {  
    param($computername) 
    New-PSDrive -PSProvider FileSystem -Name "X" -Root "\\$computername\scripts" -Persist -Verbose -Scope Global
    } -ArgumentList $computername

    #Session B checking the mapping

    $credentials = Get-Credential user
    $session = New-PSSession -ComputerName Server1 -Credential $credentials -Authentication CredSSP
    $computername = "Server2"

    Invoke-Command -Session $session -ScriptBlock { 
    get-PSDrive
    net use
    }

    Session B return:

    Status       Local     Remote                    Network
    -------------------------------------------------------------------------------
    Unavailable  X:        \\Server2\scripts    Microsoft Windows Network
    The command completed successfully.

    Am I doing something wrong?

    or this is not possible?

    I know that the mapping worked if I run the New-PSDrive on a local <g class="gr_ gr_22 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="22" id="22">powershell</g> session, but remote sessions seems to be the problem

    Thanks

    Luisao

     



    Friday, December 29, 2017 5:25 AM

All replies

  • This cannot be done due to second hop restriction.  You cannot access a third computer from a remote session.


    \_(ツ)_/

    Friday, December 29, 2017 9:01 AM
  • This cannot be done due to second hop restriction.  You cannot access a third computer from a remote session.


    \_(ツ)_/


    .. unless you configure WSManCredSSP .. ??
    Friday, December 29, 2017 11:12 AM
  • This cannot be done due to second hop restriction.  You cannot access a third computer from a remote session.


    \_(ツ)_/


    .. unless you configure WSManCredSSP .. ??

    Which is not a good idea for such a trivial issue.  Security and complexity issues.

    Group Policy can create persistent drives for all accounts.  Remoting can only create drives for admin accounts.


    \_(ツ)_/

    Friday, December 29, 2017 11:16 AM
  • Hi JRV,

    I am using WSManCredSSP on both machines, WINRM connection is performed with CredSSP.

    I am mapping a shared folder of the remote machine (just to test it), so it is not a third machine involved. Also, I used tested with an admin and no-admin user.Nothing seems to work.



    • Edited by LuisaoCaroca Friday, December 29, 2017 12:34 PM test
    Friday, December 29, 2017 12:20 PM
  • Please review and fix your post.  It is mostly unreadable.


    \_(ツ)_/

    Friday, December 29, 2017 12:23 PM
  • I am mapping a shared folder of the remote machine (just to test it), so it is not a third machine involved. Also, I used tested with an admin and no-admin user.Nothing seems to work.

    Your code works fine for me on W!0.  The drive persists  as expected.

    \_(ツ)_/

    Friday, December 29, 2017 12:27 PM
  • PS D:\scripts> Invoke-Command -Session $session -ScriptBlock {
    >>     param ($computername)
    >>     New-PSDrive -PSProvider FileSystem -Name X -Root "\\$computername\scripts" -Persist -Verbose -Scope Global
    >> } -argumentlist omega
    VERBOSE: Performing the operation "New drive" on target "Name: X Provider: Microsoft.PowerShell.Core\FileSystem Root:
    \\omega\scripts".
    
    Name           Used (GB)     Free (GB) Provider      Root                                CurrentLocation PSComputerName
    
    ----           ---------     --------- --------      ----                                --------------- --------------
    
    X                 417.81        493.10               \\omega\scripts                                     omega
    
    
    PS D:\scripts> Invoke-Command -Session $session -ScriptBlock {
    >>  
    >>  Get-PsDrive X
    >>  }
    
    Name           Used (GB)     Free (GB) Provider      Root                                CurrentLocation PSComputerName
    
    ----           ---------     --------- --------      ----                                --------------- --------------
    
    X                 417.81        493.10               \\omega\scripts                                     omega

    After removing the session the drive is removed.  Apparently this is a bug or feature in remoting.  Post your issue to "UserVoice" as it is not a scripting issue.


    \_(ツ)_/


    • Edited by jrv Friday, December 29, 2017 12:32 PM
    • Proposed as answer by jrv Friday, December 29, 2017 12:32 PM
    Friday, December 29, 2017 12:30 PM
  • done
    Friday, December 29, 2017 12:34 PM
  • BTW, both are Windows Server 2012 R2
    Friday, December 29, 2017 12:35 PM
  • Thanks, I will do it
    Friday, December 29, 2017 12:37 PM
  • Can I just move it or I need to create it again?
    • Edited by LuisaoCaroca Friday, December 29, 2017 12:38 PM bad gram
    Friday, December 29, 2017 12:37 PM
  • Can I just move it or I need to create it again?

    UserVoice is a separate site managed by an external vendor so we cannot move it.  Just post a link back to this topic with a simple example/explanation.

    Post the link to the UV topic and I and others will vote it up.


    \_(ツ)_/


    • Edited by jrv Friday, December 29, 2017 12:40 PM
    Friday, December 29, 2017 12:39 PM
  • Sorry, can you pass the link?
    Friday, December 29, 2017 1:33 PM