Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Mapping script for shares

$
0
0

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...


Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>