Author Posts

August 20, 2018 at 4:41 pm

Hello,Below is my logon script on PS command.
The code works very well.
But! All users have shared folders at Windows logon (with rights and no access rights).
How can I view only users' shared folders with access to the directory.
I am sorry for my bad english.

$ndriveobj = New-Object -Com$ndriveobj.RemoveNetworkDrive("G:", $true,)

$ndriveobj.MapNetworkDrive("H:", "\TRIESTE\Secteur accompagnement", $true)

$ndriveobj.RemoveNetworkDrive("I:", $true, $true)$ndriveobj.MapNetworkDrive("I:", "\TRIESTE\PARAMEDICAUX", $true)

$ndriveobj.RemoveNetworkDrive("J:", $true, $true)$ndriveobj.MapNetworkDrive("J:", "\TRIESTE\SECRETARIAT", $true)

$ndriveobj.RemoveNetworkDrive("K:", $true, $true)$ndriveobj.MapNetworkDrive("K:", "\TRIESTE\Secrétariat Direction", $true)

$ndriveobj.RemoveNetworkDrive("M:", $true, $true)$ndriveobj.MapNetworkDrive("M:", "\TRIESTE\LIBRE2", $true)

I am in "Windows PowerShell"


August 20, 2018 at 4:44 pm

You have to use gist (via github) or the 'pre' tags for posting script in the forum. Please edit and format it properly for others to understand properly.

August 20, 2018 at 4:56 pm

If only certain users have access, we'll assume by a Active Directory Group (or even better a OU), why not assign the policy only to those users? You need to be more clear on what your issue is.

August 20, 2018 at 6:16 pm

The code works perfectly, but it connects all network drives to all users. Is it possible that it connects only shared folders with read or edit permission.

August 20, 2018 at 6:49 pm

If you have Active Directory installed, and one of your domain controllers is at least Windows 2008 R2 – I feel like you would be better served by mapping the drives using Group Policy Preferences

August 20, 2018 at 7:09 pm

Can you help me understand better?


August 20, 2018 at 7:24 pm

Basically, there are a better methods to do what you are attempting to do with a script. If you look at the link that @stephenmbell posted, it shows you map drives using preferences. Based on what you've posted, it sounds like you want the code to determine if a drive mapping should occur, however, we are saying that you should be doing that before the script runs by defining a mapping by group in GPO preferences or assigning the policy to only users that should run the script. In summary, this seems like something that you should correct with Active Directory setup, not Powershell code.