Skip to content

Commit

Permalink
Added 2 new scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Guelfucci committed May 11, 2017
1 parent 55d031f commit f68b716
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
43 changes: 43 additions & 0 deletions setup/RootCommandsPS/os/usb lock.ps1
Original file line number Diff line number Diff line change
@@ -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 ))
}
43 changes: 43 additions & 0 deletions setup/RootCommandsPS/os/usb unlock.ps1
Original file line number Diff line number Diff line change
@@ -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 ))
}

0 comments on commit f68b716

Please sign in to comment.