I am trying to hide network path of shared folders from domain users. (windows 2013) I have found this script while searching for network drive labeling.

$a = New-Object -ComObject shell.application
$a.NameSpace( "H:\" ).self.name = "Network Drive "

If I run the script by opening power shell manually , it successfully labels the network share and hides to network path from user.

Please guide me how to make it a logon script , so that when user logs in , this script will run and his/her network drive will be renamed.

I have no idea about windows scripting. so i will be needing step by step help to make it work.

  • There is no Windows 2013. Assign User Logon Scripts, I'm not certain you can use PS out of the box for it. In addition you could always dump a script on the machine and add it to Autostart. – Seth Mar 4 '17 at 7:50
  • its active directory with 500+ machines , Very hard to as it to assgin it to autostart on individual pc. – sadia rehman Mar 4 '17 at 8:55
  • Why would it be hard to use your software deployment to do it? In addition the article points out the involved GPO to setup a login/logoff script. You would just have to put it on a share that's available for the machines. – Seth Mar 4 '17 at 9:27

Since you already have PowerShell logic that works as you confirmed and you just need to know how to get it to work from the login script, just append the logic example I provide below with your logic as needed. Just be sure that your logic to map the drives is run before this logic runs.

I provided the Setting up a Logon Script through Active Directory Users and Computers that you can review for more indepth detail of setting up a login script which is a relatively simple task.

If you're using a batch script, just append the logic to the end of the process as shown below. If you're using a VB Script, then see Run a VBScript file here to see the objShell.Run "c:\batch\test.cmd" example but you'd create and point it to \\DomainController\sysvol\<domain>\scripts\<Batch>.cmd

Example Batch Login Script

I tested and confirmed that this works as expected in a domain environment on a Windows PC with a login script from a domain user account.

<your existing batch login script logic up here>
<you will ensure the logic to map the drives has already been run>

SET TmpPSScript=%Temp%\~tmp_RenameDrive.ps1
IF EXIST "%TmpPSScript%" DEL /Q /F "%TmpPSScript%"
ECHO $a = New-Object -ComObject shell.application >>"%TmpPSScript%"
ECHO $a.NameSpace( "H:\" ).self.name = "Homes"    >>"%TmpPSScript%"

SET PowerShellDir=C:\Windows\System32\WindowsPowerShell\v1.0
CD /D "%PowerShellDir%"
Powershell -ExecutionPolicy Bypass -Command "& '%TmpPSScript%'"


Additional Resources

| improve this answer | |
  • Sadia - Additionally I wanted to add since you're in an AD domain environment, you could use Group Policy Preferences to map network drives based on security group membership which has a "label" field that does this same for of thing for a mapped network drive on Windows OSes. I've used this method and it works solidly and once setup it's just a matter of adding the user account(s) you wish to have it to the security group.Here's a tutorial with screen shot, etc. from 2009 but it appears to be applicable still from what I can tell settings wise with GPP and AD. – Pimp Juice IT Mar 8 '17 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.