-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap-network-drives.ps1
33 lines (24 loc) · 1.03 KB
/
map-network-drives.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$pathFelles = "\\15hovfil01.nssr.local\felles$"
$pathHome = "\\15hovfil01.nssr.local\home$\$env:username"
$pathOrgys = "\\15hovorg01.nssr.local\ekstern"
$pathMaler = "\\15hovfil01.nssr.local\maler"
function mapNetworkDrive([string]$Name, [string]$Path) {
$MappedDrive = (Get-PSDrive -Name $Name -ErrorAction SilentlyContinue)
#Check if drive is already mapped
if ($MappedDrive) {
#Drive is mapped. Check to see if it mapped to the correct path
if ($MappedDrive.DisplayRoot -ne $Path) {
# Drive Mapped to the incorrect path. Remove and readd:
Remove-PSDrive -Name $Name
New-PSDrive -Name $Name -Root $Path -Persist -PSProvider "FileSystem" -Scope Global
}
}
else {
#Drive is not mapped
New-PSDrive -Name $Name -Root $Path -Persist -PSProvider "FileSystem" -Scope Global
}
}
mapNetworkDrive -Name "U" -Path $pathFelles
mapNetworkDrive -Name "Z" -Path $pathHome
mapNetworkDrive -Name "M" -Path $pathMaler
mapNetworkDrive -Name "O" -Path $pathOrgys