PowerShell: Map Network Drive

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:

function New-MapDrive {
    param($Path) 
    $present = @(Get-WmiObject Win32_Networkconnection |
       Select-Object -ExpandProperty RemoteName)
    if ($present -contains $Path) {
        "Network connection to $Path is already present"
    } else {
        net use * $Path
    }
}

One Response to “PowerShell: Map Network Drive”

  1. Shaniqua Zelek December 20, 2012 at 9:05 am #

    Greetings from across the sea! This is just what I was expecting, and you nailed it. Thanks very much

Leave a Reply

revia in alcoholism