I have been struggling to get into the next phrase of testing towards creating a logon script that will map drives if they belong to a Group and removed if they don't. This is on top of a few drives that needs to be mapped by default.
Below is my simple code, but when I tried to test it won't execute the one inside the if condition even though the condition has been met. I have run gpupdate and restart the test computer several times, but to no avail.
Import-Module ActiveDirectory
$user = $env:USERNAME
#--------- Checking for XCOMP Group ----------
if ((Get-AdGroupMember -Identity "XCOMP" -Recursive | Where-Object { $_.SamAccountName -eq $User }))
{
$ServerMap = "\\servernetwork\Share Drive"
$MappVariable = Test-Path $ServerMap
if ($MappVariable) {
net use M: $ServerMap
}
}
else
{
net use M: /delete
}
Any chance one has the idea as to why? or any other code that is more efficient than this?
Thank you so much team!
- Around condition operator or another cmdlet.