mapping network shares from domain - multiple if's

Welcome Forums General PowerShell Q&A mapping network shares from domain - multiple if's

Viewing 2 reply threads
  • Author
    Posts
    • #53810
      Participant
      Topics: 5
      Replies: 9
      Points: 0
      Rank: Member

      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
      Participant
      Topics: 0
      Replies: 17
      Points: 1
      Rank: Member

      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.

    • #53827
      Participant
      Topics: 5
      Replies: 9
      Points: 0
      Rank: Member

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

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

Viewing 2 reply threads
  • The topic ‘mapping network shares from domain - multiple if's’ is closed to new replies.