nicolonsky / IntuneDriveMapping

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

Removing disconnected obsolete drives #19

Closed Billie123456 closed 3 years ago

Billie123456 commented 4 years ago

First of all thank you so much for this script i've been using it for a long while now in combination with intune.

There is one issue I have and that is that remove-psdrive wont remove disconnected drives and most drive mappings I want replaced are no longer mapped as the share is no longer available. Get-Psdrive wont see them so they wont get removed by the "mapped with wrong config part of the script" Would it be possible to rewrite this part of the script using the get-smbmapping and remove-smbmapping commands? I am aware of the new "remove unnasigned drives" option which is great, but I just want to remove drives that do not match the company drives. For now I just added a few lines in manually using remove-smbmapping and then listing my obsolete drives by hand, but it would be much nicer if it was dynamic as the current "mapped with wrong config" part of the script.

nicolonsky commented 4 years ago

Thanks for the feedback. Can't really follow your idea because how could we determine if it was a corp drive/drive which got mapped manually. But feel free to submit a pull request with your proposed changes for the template https://github.com/nicolonsky/IntuneDriveMapping/blob/master/IntuneDriveMapping/wwwroot/bin/IntuneDriveMappingTemplate.ps1

Billie123456 commented 4 years ago

It's not a corperate drive persé that was mapped manually but a drive that was migrated to a new server so the unc path was changed (although you want manually mapped drives that use a drive letter the company uses to be removed as well).

The way to determine is the same way you are checking for the wrong config right now by these lines:

# Mapped with wrong config -> Delete it
Get-PSDrive | Where-Object { $_.DisplayRoot -eq $drive.Path -or $_.Name -eq $drive.DriveLetter } | Remove-PSDrive -EA SilentlyContinue

But then use remove-SmbMapping instead of remove-Psdrive as that doesnt do disconnected drives

I am not very good with powershell myself but ill try and rewrite it