Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a Powershell script to map drives based on IP addresses. Here are the req

ID: 3732894 • Letter: I

Question

I need a Powershell script to map drives based on IP addresses. Here are the requirements:

1) Create a script named drivemap.ps1

2) Create folders on your C drive root and name them after the departments

3) Have the script discover the IP address and convert to array of octet values

4) Check the first two octets for a match to make sure the IP address is correct for this building

5) In your script, have it map the associated drive letter to the corresponding folder on your C drive based on the discovered IP address’ third octet

Explanation / Answer

#fdiscover the ipaddress

$ipadd4 = (Test-Connection -ComputerName $env:computername -count 1).IPV4Address.ipaddressTOstring

#display the ipaddress

echo "ipaddress : $ipadd4"

# Create array of octet in ipaddress

$sp_ip = $ipadd4.Split('.')

#display upto 3rd octet

$sp_ip[0]
$sp_ip[1]
$sp_ip[2]

# matched the first 2 octet, if true then go for 3rd octet

if ($sp_ip[0] -eq 192 -and $sp_ip[1]-eq 168) {
echo "Got correct ip address"

# Map drives based on third octet
if ($sp_ip[2] -eq 1) {

#share the drive with K with the create folder

New-PSDrive -NAME "K" -PSProvider FileSystem -Root "\desktop1C$ccounts"

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote