Lock-BitLockerVolume
Windows: Locks an unlocked BitLocker volume
#Requires -Version 5.1
#Requires -Modules BitLocker
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[string]$MountPoint,
[switch]$ForceDismount,
[string]$ComputerName = $env:COMPUTERNAME,
[pscredential]$Credential
)
Process {
try {
$scriptBlock = {
Param($Drive, $Force)
Lock-BitLocker -MountPoint $Drive -ForceDismount:$Force -Confirm:$false -ErrorAction Stop
Get-BitLockerVolume -MountPoint $Drive | Select-Object MountPoint, VolumeStatus, ProtectionStatus
}
if ($ComputerName -ne $env:COMPUTERNAME) {
$invokeParams = @{
'ComputerName' = $ComputerName
'ScriptBlock' = $scriptBlock
'ArgumentList' = @($MountPoint, $ForceDismount)
'ErrorAction' = 'Stop'
}
if ($null -ne $Credential) {
$invokeParams.Add('Credential', $Credential)
}
$result = Invoke-Command @invokeParams
}
else {
$result = &$scriptBlock -Drive $MountPoint -Force $ForceDismount
}
$output = [PSCustomObject]@{
MountPoint = $result.MountPoint
VolumeStatus = $result.VolumeStatus
ProtectionStatus = $result.ProtectionStatus
ComputerName = $ComputerName
Action = "VolumeLocked"
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $output
}
catch {
throw
}
}Specifies the drive letter or mount point (e.g., "D:").
Off
If set, forces the volume to lock even if it is currently in use.
Specifies the name of the target computer. Defaults to the local computer.
Specifies a PSCredential object for remote connection.