Search code examples
windowspowershellnet-use

Equivalent of net use (to list computer's connections) in powershell?


According to windows help NET USE, when used without options, lists the computer's connections.

I'd like to find a way in powershell to get a list of the Remote entries in net use's output.

I know that as an extreme measure I can parse the result of the "net use" command itself, but I'd rather not rely on the text output of that command.

Can anybody help me out? thank you

Michele

Status       Local     Remote                    Network  
-------------------------------------------------------------------------------  
OK                     \\SERVER02\example          Microsoft Windows Network  
OK                     \\SERVER02\prova            Microsoft Windows Network  
Disconnected           \\SERVER03\test             Microsoft Windows Network  
OK                     \\SERVER02\remoteshare      Microsoft Windows Network  
Disconnected           \\SERVER03\remoteshare   

Solution

  • For the mapped logical drive you can use WMI class Win32_MappedLogicalDisk :

    Get-WmiObject Win32_MappedLogicalDisk
    

    Here is another way with Win32_LogicalDisk :

    PS C:\> Get-WmiObject -Query "Select * From Win32_LogicalDisk Where DriveType = 4"
    
    DeviceID     : V:
    DriveType    : 4
    ProviderName : \\jpbdellf1\c$
    FreeSpace    :
    Size         :
    VolumeName   :
    

    Edited

    You are right, you can get what you need with Win32_NetworkConnection :

    PS > Get-WmiObject Win32_NetworkConnection
    
    LocalName                     RemoteName                    ConnectionState               Status
    ---------                     ----------                    ---------------               ------
                                  \\jpbasusf1\temp              Connected                     OK
    

    On Seven or W2K8 be careful to call this with the same user that run the NET USE because it's a session information.