Permalink
Branch: master
Find file Copy path
9217407 Jan 10, 2019
1 contributor

Users who have contributed to this file

79 lines (50 sloc) 2.01 KB
Start-Transcript -Path $(Join-Path $env:temp "DriveMapping.log")
$driveMappingConfig=@()
######################################################################
# section script configuration #
######################################################################
<#
Add your internal Active Directory Domain name and custom network drives below
#>
$dnsDomainName= "tech.nicolonsky.ch"
$driveMappingConfig+= [PSCUSTOMOBJECT]@{
DriveLetter = "P"
UNCPath= "\\vfs01.tech.nicolonsky.ch\pool"
Description="Pool"
}
$driveMappingConfig+= [PSCUSTOMOBJECT]@{
DriveLetter = "T"
UNCPath= "\\vfs01.tech.nicolonsky.ch\software"
Description="Software"
}
$driveMappingConfig+= [PSCUSTOMOBJECT]@{
DriveLetter = "V"
UNCPath= "\\vfs01.tech.nicolonsky.ch\archiv"
Description="Archiv"
}
######################################################################
# end section script configuration #
######################################################################
$connected=$false
$retries=0
$maxRetries=3
Write-Output "Starting script..."
do {
if (Resolve-DnsName $dnsDomainName -ErrorAction SilentlyContinue){
$connected=$true
} else{
$retries++
Write-Warning "Cannot resolve: $dnsDomainName, assuming no connection to fileserver"
Start-Sleep -Seconds 3
if ($retries -eq $maxRetries){
Throw "Exceeded maximum numbers of retries ($maxRetries) to resolve dns name ($dnsDomainName)"
}
}
}while( -not ($Connected))
#Map drives
$driveMappingConfig.GetEnumerator() | ForEach-Object {
Write-Output "Mapping network drive $($PSItem.UNCPath)"
New-PSDrive -PSProvider FileSystem -Name $PSItem.DriveLetter -Root $PSItem.UNCPath -Description $PSItem.Description -Persist -Scope global
(New-Object -ComObject Shell.Application).NameSpace("$($PSItem.DriveLEtter):").Self.Name=$PSItem.Description
}
Stop-Transcript