CLSegraves
Explorer
- Joined
- Sep 13, 2013
- Messages
- 84
Hey everyone, I need some guidance on how to accomplish something.
I want to write a script that will check to see if my laptop can see the NAS (my NAS on my local/home network), and if so, map the drives. Otherwise (ie: I’m not at home), I don’t want Windows to bother trying to map the drives.
My idea was to run a test-connection script that would go out and try to find the NAS. The following powershell command:
Test-connection –Computername NAS01 –Buffersize 16 –Count 1 –Quiet
returns a “True” (if the NAS is there), but I am not sure where to go from there. From back in the day when I did some java programing, I had thought to use an
if (test-connection***** = True)
{
"map drives"
}
but I'm not sure of the exact verbiage in windows.
On login/wakeup I would have Windows execute a bat file with the “if” statement that would execute the test-connection command and if a “True” is returned, execute the following to map the drive:
@echo off
ping localhost -n %delay%
net use E: "\\SomePC\SomeShare"
net use F: "\\SomePC\SecondShare"
net use G: "\\SomePC\ThirdShare"
I use this mapping (along with a short delay) on my home desktop to keep from Windows trying to automatically map my network drives on startup (my desktop takes a few seconds to initialize and get an IP).
Ideas?
Thanks,
Chris
I want to write a script that will check to see if my laptop can see the NAS (my NAS on my local/home network), and if so, map the drives. Otherwise (ie: I’m not at home), I don’t want Windows to bother trying to map the drives.
My idea was to run a test-connection script that would go out and try to find the NAS. The following powershell command:
Test-connection –Computername NAS01 –Buffersize 16 –Count 1 –Quiet
returns a “True” (if the NAS is there), but I am not sure where to go from there. From back in the day when I did some java programing, I had thought to use an
if (test-connection***** = True)
{
"map drives"
}
but I'm not sure of the exact verbiage in windows.
On login/wakeup I would have Windows execute a bat file with the “if” statement that would execute the test-connection command and if a “True” is returned, execute the following to map the drive:
@echo off
ping localhost -n %delay%
net use E: "\\SomePC\SomeShare"
net use F: "\\SomePC\SecondShare"
net use G: "\\SomePC\ThirdShare"
I use this mapping (along with a short delay) on my home desktop to keep from Windows trying to automatically map my network drives on startup (my desktop takes a few seconds to initialize and get an IP).
Ideas?
Thanks,
Chris
Last edited: