I grab mapped drives from a remote machine using powershell as part of a script to move their settings to a persons' new machine: (set $OldComputer to the name or IP of the old computer) It goes through the list of all drives on the remote system, and if they are not local drives, it will attempt to remove that drive mapping on the current computer (in case its used by something else) then remap it. Comment out the second to last line (the one above foreach, and add your own line to log or msgbox if you want.)
$netObj = New-Object -com wscript.Network
$WMI1 = [WMISearcher] "Select Name, Providername from win32_mappedLogicalDisk"
$WMI1.Scope.path="\\" + $oldComputer + "\root\cimv2"
$WMI1.Options.ReturnImmediately
$ColDrives = $WMI1.Get()
foreach ($objDrive in $colDrives) {
$TestLocal = get-wmiObject Win32_LogicalDisk | ? {$_.DeviceID -eq $objDrive.Name} | % {$_.Providername}
If ($TestLocal) {
Net Use /Delete $objDrive.Name >> $LogFile
}#If
#Map the drive
Net use $objDrive.Name $objDrive.ProviderName >> $LogFile
}#foreach
Local System
?