mapping network shares from domain - multiple if's


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…


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.

I’m really THAT dumb!!!?

I can’t believe I did that… god damnit…!