Logon script PS

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 wscript.network$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”


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.

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.

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.

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

Can you help me understand better?


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.