locked
how to check the network drive is still map to the netwrok RRS feed

  • Question

  • I have a server 2016 , it is map another server via samba , however , the connection is always broken .

    Therefore , I just would like to check if the drives are still connected , dose powershell can do so , would advise how to write such powershell to do that ?

    thanks

    Thursday, December 27, 2018 8:25 AM

All replies

  • I think this should work for a mapped drive ...just change the drive letter and computer name 

    $disk = Get-WmiObject Win32_LogicalDisk -ComputerName remotecomputer -Filter "DeviceID='C:'" |
    Select-Object Size,FreeSpace
    
    $disk.Size
    $disk.FreeSpace

    https://stackoverflow.com/questions/12159341/how-to-get-disk-capacity-and-free-space-of-remote-computer


    Thursday, December 27, 2018 8:16 PM
  • I think it qould better to use the new WMI cmdlets like get-ciminstance

    $Connection =get-ciminstance -ClassName win32_logicaldisk | ? {($_.drivetype -eq 4) -an d ($_.ProviderName -eq "<UNC Path to the connected networkshare")} if (!$Connection) {

    write-error "Connection lost"

    New-PSDrive -Name <Driveletter> -PSProvider FileSystem -Root <UNC Path to Network Share> -Credential <Credentials>

    }



    regards Thomas Paetzold visit my blog on: http://sus42.wordpress.com


    • Edited by Peddy1st Friday, January 4, 2019 4:15 PM
    Friday, January 4, 2019 4:15 PM
  • Using Net use should work too through command prompt.. 

    Simply; 

    CMD

    in CMD

    Type in Net Use

    You should see all mapped drives, available.. 

    A better question might be, why do the drives keep breaking connection? 


    Rob

    Friday, January 4, 2019 4:23 PM
  • drives disconnect automatically after a delay.  They reconnect when accessed.  The issue is with non-Windows devices and cannot be remedied in Windows.

    See the following:

    PS C:\WINDOWS\system32> net config server
    Server Name                           \\ALPHA
    Server Comment
    
    Software version                      Windows 10 Pro
    Server is active on
            NetbiosSmb (ALPHA)
            NetBT_Tcpip_{8AEC8419-2BC6-48B3-A51C-14D7410DCC93} (ALPHA)
    
    
    Server hidden                         No
    Maximum Logged On Users               20
    Maximum open files per session        16384
    
    Idle session time (min)               15
    The command completed successfully.
    
    PS C:\WINDOWS\system32>
    
    

    "Idle session timeout" controls this.net

    net config server /?

    Set Autodisconnect time.

    See KB article: https://support.microsoft.com/en-us/help/297684/mapped-drive-connection-to-network-share-may-be-lost


    \_(ツ)_/

    Friday, January 4, 2019 4:40 PM
  • drives disconnect automatically after a delay.  They reconnect when accessed.  The issue is with non-Windows devices and cannot be remedied in Windows.

    See the following:

    PS C:\WINDOWS\system32> net config server
    Server Name                           \\ALPHA
    Server Comment
    
    Software version                      Windows 10 Pro
    Server is active on
            NetbiosSmb (ALPHA)
            NetBT_Tcpip_{8AEC8419-2BC6-48B3-A51C-14D7410DCC93} (ALPHA)
    
    
    Server hidden                         No
    Maximum Logged On Users               20
    Maximum open files per session        16384
    
    Idle session time (min)               15
    The command completed successfully.
    
    PS C:\WINDOWS\system32>
    

    "Idle session timeout" controls this.net

    net config server /?

    Set Autodisconnect time.

    See KB article: https://support.microsoft.com/en-us/help/297684/mapped-drive-connection-to-network-share-may-be-lost


    \_(ツ)_/

    So.. why is it on a Microsoft forum? 

    What is the linux system? 

    Is it Cent, Redhat, Ubuntu.. 

    are these straight SAMBA or are they CIFs? 


    Rob

    Friday, January 4, 2019 4:53 PM
  • So.. why is it on a Microsoft forum? 

    What is the linux system? 

    Is it Cent, Redhat, Ubuntu.. 

    are these straight SAMBA or are they CIFs? 


    Rob

    The connection is to a Samba server.  MS disconnects ALL sessions after 15 minutes and reconnects automatically on demand.  Old versions of Samba may need upgrading or need to be reconfigured. This can also be caused by network issues or a server that is restarted.  Setting AutoDisconnect to 0 can sometimes fix this.  

    This  is not a scripting issue and not a scripting solution.


    \_(ツ)_/

    • Proposed as answer by themanindbox Friday, January 4, 2019 5:06 PM
    Friday, January 4, 2019 5:01 PM
  • P.S. - Samba is usually SMB which is likely where it gets its name.  SMBv1 is an unsecure and dangerous protocol and subject to attacks by malware.  This can be a source of drive unavailability on a reconnect or loss of access on a connected drive.  The outage is usually intermittent making it appear as a disconnect problem as a reconnect will get a new set of ports.  Checking the server for port usage may help to detect this.

    SMBv1 should be disabled.  GThe following KB article describes how to manipulte SMB protocols to troubleshoot issues.

    https://support.microsoft.com/en-us/help/2696547/how-to-detect-enable-and-disable-smbv1-smbv2-and-smbv3-in-windows-and

    Get-SmbServerConfiguration
    Set-SmbServerConfiguration

    SMBv1 should be disabled everywhere in a network.  If Samba has not been upgraded to use SMBv2/3 then it should be upgraded for security and performance issues.


    \_(ツ)_/

    Friday, January 4, 2019 5:21 PM