May 022012
 

Map Network Drive with Powershell

Sure you can use the command net use to map a network drive. But this would not check for existing mapped drives. Here’s a small function that first checks to see that the URL you are mapping to does not yet exist, avoiding duplicate mapped drives:

 

functionNew-MapDrive {
param($Path)

    $present= @(Get-WmiObjectWin32_Networkconnection|
       Select-Object-ExpandPropertyRemoteName)

    if ($present-contains$Path) {
“Network connection to
$Path is already present”

    } else {
netuse*$Path
    }
}