Good day again!
Network drives are commonly used in many companies. Whether they have a H: drive linking to their home drives or some other drive letters linking to specific shares on file servers .. these are commonly used ways of allowing people to access files that are saved on servers, storage devices or other remote places.
These drive letters are usually spread around by different methods ranging from group policy, workstation management software or manually added by customers.
However, some times something changes that requires the old shares to be removed due to being invalid or outdated.
When you have customers with clusters of network drives of which some are new/correct and others are invalid, it can become annoying to manage.
The script is quite simple and only has a niche usage, but can nonetheless be quite useful.
The idea is simple. You fill in a partial/important part of the TARGET of the network drive, the script looks through all the drive letters and disconnects everything going towards that target.
Before a customer had multiple network drives to a file server (lets call it FS01), however now they have their files on a new server (lets call it FS02). A group policy has added drives to the new FS02, however some people still have either manually added drives towards FS01 folders or have not had these old drives removed.
All I have to do is put in a difference as variable.. so in this case
$TargetVariabele = "FS01"
The script gets all the drive letters, checks where they go and disconnects everything that has FS01 in the targeturl.
It is a very easy script. It simply gets all letters using a get-wmiobject whereby it gets the drive letter and target (aka, provider name). It then checks whether the variable in any way is present in the targeturl and if so, disconnects the drive.
!! Make sure the script is run under the user that has the drives. Running this under a SYSTEM user won't have much use as the drives are user-specific. !!
Hopefully this will end up helping someone save a bit of time,
Categories: Powershell, User, Network Drive, Script, Windows
Patrick Berger AKA Powershellder.
[ i ] Parallax section below. Click on the section below to upload image. Don't worry if it looks weird in the Weebly editor. It'll look normal on your published site.
To edit or delete your image, press the "toggle" button below. Then, hover over your image until a popup appears with the "edit" and "delete" options. If you don't want a white content section, leave it blank. It will disappear on your live website.