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   
                The Net Use command is commonly used to add or remove network connections from a computer. One of the advantages of using a command for this is that you can add a drive letter after somebody logs in. Or easily create a script that will add the network connection on multiple computers.
This net use command is used to cancel a network connection. Use /delete with devicename to remove a specified connection or with * to remove all mapped drives and devices. This option can be shortened to /d.
Use net use to connect to and disconnect from a network resource, and to view your current connections to network resources. You cannot disconnect from a shared directory if you use it as your current drive or an active process is using it.
“Net use” is a command line method of mapping network drives to your local computer. The full syntax for net use is available from Microsoft . The Username and Password parameters are only required if the computer is not CornellAD joined.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With