none
Network Drive mapping script RRS feed

  • General discussion

  • Hi,

    Basically I am trying to disconnect shares from old DC1 server and map shares on a new DC2 server (having the same permissions and same share names)

    BAT script runs a PS script (to disconnect drives) and then executes map commands.

    BAT script
    @echo off
    #runs a PS script
    PowerShell.exe -ExecutionPolicy Bypass -Command "& '%~dpn0.ps1'"
    #maps drives  
    net use * \\dc2\production /P:Yes
    net use * \\dc2\finance /P:Yes

    PS script
    #Delete drives
    Import-Module activedirectory
    $mapped = Get-WmiObject Win32_MappedLogicalDisk | Select DeviceId, ProviderName
    foreach ($item in $mapped) {
        if ($item.ProviderName -eq '\\DC1\production') {net use $item.DeviceId /del}
    }
    $mapped = Get-WmiObject Win32_MappedLogicalDisk | Select DeviceId, ProviderName
    foreach ($item in $mapped) {
        if ($item.ProviderName -eq '\\DC1\finance') {net use $item.DeviceId /del}
    }

    Everything works well. But I am facing an issue that all of the shared drives are still mapped on everyone's PC regardless if they have access to the share or not(they remain mapped but you are unable to access the share obviously). So I was wondering is there a way that PS or BAT script could check if the share exists on laptop and if it does it would map a share and if it does not it would just skip mapping that particular share?  

    MK

    • Changed type Bill_Stewart Friday, July 7, 2017 6:58 PM
    • Moved by Bill_Stewart Friday, July 7, 2017 6:59 PM This is not "research solution for me" forum
    Wednesday, May 31, 2017 12:56 PM

All replies