Advertisement
Yevrag35

Remove Drive Letter

Jul 24th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.     .SYNOPSIS
  3.         Removes the drive letter from a drive with the specified volume name.
  4.     .DESCRIPTION
  5.         Author:     Mike Garvey
  6.         Published:  12/1/2018
  7.         Version:    1.0
  8.  
  9.         When imaging a UEFI-enabled workstation, SCCM incorrectly allows for the 'Recovery'
  10.         partition to be assigned a drive letter.  This script, when run at the end of a task
  11.         sequence, removes this drive letter if it exists.
  12.        
  13.     .PARAMETER VolumeName
  14.         The labeled volume name of the recovery drive.  Normally, defaults to 'Recovery'.
  15.  
  16.     .INPUTS
  17.         Does not accept pipeline input.
  18.     .OUTPUTS
  19.         None.
  20.     .EXAMPLE
  21.         .\RemoveDriveLetter.ps1 -VolumeName 'Recovery'
  22.     .NOTES
  23.         This script will not remove any drive letters on volumes that do NOT match the specified name.
  24. #>
  25. #Requires -Modules Storage -RunAsAdministrator
  26. [CmdletBinding(PositionalBinding=$false)]
  27. param
  28. (
  29.     [parameter(Mandatory=$false)]
  30.     [string] $VolumeName = "Recovery"
  31. )
  32.  
  33. $volume = Get-Volume -FileSystemLabel $VolumeName;
  34. if ($null -ne $volume)
  35. {
  36.     $volume | Get-Partition | Remove-PartitionAccessPath -AccessPath "$($volume.DriveLetter):\" -Confirm:$false;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement