diff --git a/setup/RootCommandsPS/os/usb lock.ps1 b/setup/RootCommandsPS/os/usb lock.ps1 new file mode 100644 index 0000000000..a61571dc67 --- /dev/null +++ b/setup/RootCommandsPS/os/usb lock.ps1 @@ -0,0 +1,43 @@ +# Check if a give drive is locked or not. +function IsLocked( $drive ) +{ + return (manage-bde -status $drive| Select-String -Pattern 'Lock Status').ToString().Split(":")[1].trim().ToLower() -eq "locked" +} + +# keep track of what we locked +# so we can give a summary at the end. +$found = 0; + +# Look for all the unlocked drives. +$drives = Get-WmiObject Win32_Volume -Filter ("DriveType={0}" -f [int][System.io.Drivetype]::removable) + +# for each and every drives we found. +foreach( $drive in $drives ) +{ + # is it locked? + if( (IsLocked( $drive.DriveLetter )) -eq $false) + { + # add a message to say that we are locking this drive. + [void]($am.Say( "Drive : "+$drive.DriveLetter +" is unlocked", 400, 10 )) + + # lock it + manage-bde -lock $drive.DriveLetter + + # track that we found an unlocked drive + $found++; + } + + # Move on to the next drive +} + +# Give some sort of sumarry of what was done. +if( $found -eq 0 ) +{ + # If we locked nothing just tell the user. + [void]($am.Say( "Could not find any drives to lock", 400, 10 )) +} +else +{ + # Otherwise just tell them how many we locked. + [void]($am.Say( "Found : "+$found +" drive(s) to lock", 400, 10 )) +} \ No newline at end of file diff --git a/setup/RootCommandsPS/os/usb unlock.ps1 b/setup/RootCommandsPS/os/usb unlock.ps1 new file mode 100644 index 0000000000..35e7309d34 --- /dev/null +++ b/setup/RootCommandsPS/os/usb unlock.ps1 @@ -0,0 +1,43 @@ +# Check if a give drive is locked or not. +function IsLocked( $drive ) +{ + return (manage-bde -status $drive| Select-String -Pattern 'Lock Status').ToString().Split(":")[1].trim().ToLower() -eq "locked" +} + +# keep track of what we unlocked +# so we can give a summary at the end. +$found = 0; + +# Look for all the locked drives. +$drives = Get-WmiObject Win32_Volume -Filter ("DriveType={0}" -f [int][System.io.Drivetype]::removable) + +# for each and every drives we found. +foreach( $drive in $drives ) +{ + # is it locked? + if( (IsLocked( $drive.DriveLetter )) -eq $true) + { + # add a message to say that we are unlocking this drive. + [void]($am.Say( "Drive : "+$drive.DriveLetter +" is locked", 400, 10 )) + + # unlock it, (and ask for password) + manage-bde -unlock $drive.DriveLetter -Password + + # track that we found a locked drive + $found++; + } + + # Move on to the next drive +} + +# Give some sort of sumarry of what was done. +if( $found -eq 0 ) +{ + # If we unlocked nothing just tell the user. + [void]($am.Say( "Could not find any drives to unlock", 400, 10 )) +} +else +{ + # Otherwise just tell them how many we unlocked. + [void]($am.Say( "Found : "+$found +" drive(s) locked", 400, 10 )) +} \ No newline at end of file