Hi, I am having issues trying to map drives based on IP Addresses using Powershell. We have four locations with the following IP, Location1 20.30.40_ Location2 20.30.50_ & so on. Currently I have the below setup;
PowerShell Script To Map NetworkDrive based on IP Address
$ErrorActionPreference = "SilentlyContinue"
$Shell = New-Object -Com WScript.Shell
$Network = New-Object -Com WScript.Network
$UserName = $Network.UserName
$User = Get-ADUser -Indentity $UserName
$Computer = "."
$Nic = Get-CimInstance -Computer $computer -class Win32_NetworkAdapterConfiguration -Filter IPEnabled = True"
Foreach ($Item in $colItems {
ForEach $Address in $IPAddress) {
$IPAddress = Split($Address, ".")
If (($IPAddress[0] -ne 10) -And ($IPAddress[1] -ne 20) {$Address = $IPAddress[2]}
}
}
If $IPAddress[0] -EQ 20 And $IPAddress[1] -EQ 30 And $IPAddress[2] -EQ 40 Then
Get-PSDrive S | Remove-PSDrive
New-PSDrive -Name "S" -Root "\\wide\setup" -Persist -PSProvider "FileSystem"
If $IPAddress[0] -EQ 20 And $IPAddress[1] -EQ 30 And $IPAddress[2] -EQ 50 Then
Get-PSDrive P | Remove-PSDrive
New-PSDrive -Name "P" -Root "\\wide\prog" -Persist -PSProvider "FileSystem"