mapping network shares from domain - multiple if's

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Martin Thomsen Martin Thomsen 2 weeks, 6 days ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #53810
    Profile photo of Martin Thomsen
    Martin Thomsen
    Participant

    Hi

    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...

    ideas?

    #53815
    Profile photo of 84rusty .
    84rusty .
    Participant

    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 2 weeks, 6 days ago by Profile photo of 84rusty . 84rusty ..
    • This reply was modified 2 weeks, 6 days ago by Profile photo of 84rusty . 84rusty ..
    #53827
    Profile photo of Martin Thomsen
    Martin Thomsen
    Participant

    OMG!!!!
    I'm really THAT dumb!!!?

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

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.