nicolonsky / IntuneDriveMapping

Generate PowerShell scripts to map network drives on Intune managed Windows 10 devices
https://intunedrivemapping.azurewebsites.net/
MIT License
148 stars 17 forks source link

Multiple security groups #32

Closed Phenix51 closed 2 years ago

Phenix51 commented 3 years ago

First, thank you for this. It has saved me quite a bit of time.

This isn't an issue per-say but I'm curious if you're able to specify more than one security group within each drive mapping? How is the code supposed to be structured for that GroupFilter? Or is it 'best' to have one security group per path item?

I've tried a few methods I thought would work but I haven't been successful thus far. Any guidance would be appreciated.

zparta commented 3 years ago

Hi.

I took it upon myself to fix this issue, i dont want to commit the change but i have created an easy code replace for the finnished .ps1 file, this might not be the best way to fix this but it works.

When you generate through his generator just enter multiple groups with a comma(,) as delimiter eg. "Group1,Group2" do not put any space around the comma.

Then replace this row

$driveMappingConfig = $driveMappingConfig | Where-Object { $groupMemberships -contains $_.GroupFilter -or $_.GroupFilter -eq $null }

with this code:

$driveMappingConfigCleaned = @() foreach ($mapping in $driveMappingConfig) { if($mapping.GroupFilter -ne $null -and $mapping.GroupFilter.Contains(",")) { $Agroups = $mapping.GroupFilter.Split(",") foreach ($Agroup in $Agroups) { if ($groupMemberships -contains $Agroup) { $mapping.GroupFilter = $Agroup $driveMappingConfigCleaned += $mapping break } } } else { if ($groupMemberships -contains $mapping.GroupFilter -or $mapping.GroupFilter -eq $null) { $driveMappingConfigCleaned += $mapping } } } $driveMappingConfig = $driveMappingConfigCleaned

zparta commented 3 years ago

A different approach that uses Compare-Object instead.

$driveMappingConfigCleaned = @() foreach ($mapping in $driveMappingConfig) { if($mapping.GroupFilter -ne $null -and $mapping.GroupFilter.Contains(",")) { $Agroups = $mapping.GroupFilter.Split(",") $value = Compare-Object -ReferenceObject $Agroups -DifferenceObject $groupMemberships -IncludeEqual -ExcludeDifferent -PassThru if($value.Count -gt 0) { $driveMappingConfigCleaned += $mapping } } else { if ($groupMemberships -contains $mapping.GroupFilter -or $mapping.GroupFilter -eq $null) { $driveMappingConfigCleaned += $mapping } } } $driveMappingConfig = $driveMappingConfigCleaned

AndreasRogge commented 2 years ago

I also added a pull request quite a time ago. You can see my code there. But it seems like this repo won't get updated anymore.

nicolonsky commented 2 years ago

https://github.com/nicolonsky/IntuneDriveMapping/pull/27