Logon script PS

Welcome Forums General PowerShell Q&A Logon script PS

This topic contains 6 replies, has 4 voices, and was last updated by

 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #109049

    Participant
    Points: 0
    Rank: Member

    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"

     

  • #109054

    Participant
    Points: 878
    Helping Hand
    Rank: Major Contributor

    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.

  • #109058

    Participant
    Points: 324
    Helping Hand
    Rank: Contributor

    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.

  • #109069

    Participant
    Points: 0
    Rank: Member

    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.

  • #109072

    Participant
    Points: 93
    Rank: Member

    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

  • #109081

    Participant
    Points: 0
    Rank: Member

    Can you help me understand better?

    Merci

  • #109082

    Participant
    Points: 324
    Helping Hand
    Rank: Contributor

    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.

The topic ‘Logon script PS’ is closed to new replies.