mapping network shares from domain - multiple if's

This topic contains 2 replies, has 2 voices, and was last updated by  Martin Thomsen 1 year, 10 months ago.

  • Author
  • #53810

    Martin Thomsen


    I've been playing with mapping network shares from domain fileserver to local computer. A small project for the users who often log on via VPN and thus doesn't not have a domain connection while logging in..

    $DriveletterF="DOMAIN\SG – GPO – DriveMaps – ARD – Logistik"
    $DriveletterG="DOMAIN\SG – GPO – DriveMaps – QUB – Marketing"

    $groups=Get-AllUserGroups | Where-Object {$_ -like "*SG – GPO – DriveMaps*" }

    Foreach ($group in $groups)

    #write-host $group
    if ($group = $driveletterF)
    Remove-PSDrive -Name F -Force
    new-psdrive -Name "F" -PSProvider FileSystem -Root "\\domain.local\arden\logistik"


    if ($group = $driveletterG)
    Remove-PSDrive -Name G -Force
    new-psdrive -Name "G" -PSProvider FileSystem -Root "\\domain.local\arden\marketing"


    but if I am not member of $driveletterG group then it tries to map it anyway...
    I am thinking that it must be something to do with the if's in the foreach but not sure what...


  • #53815

    84rusty .

    Hi Martin,

    Change: if ($group = $driveletterF)
    To: if ($group -eq $driveletterF)
    And same for: if ($group = $driveletterG)
    to: if ($group -eq $driveletterG)

    When you type $group = $driveletterG (with equals sign), you are assigning the value in $driveletterG to $group.

    When you use -eq you are comparing, instead of assigning a value.

    • This reply was modified 1 year, 10 months ago by  84rusty ..
    • This reply was modified 1 year, 10 months ago by  84rusty ..
  • #53827

    Martin Thomsen

    I'm really THAT dumb!!!?

    I can't believe I did that... god damnit..!

You must be logged in to reply to this topic.