0

I have a basic understanding of PowerShell.

I would like to get my hands on a PowerShell script that will run at logoff.

This script needs to warn a user that their USB storage device is still plugged in before they sign out and they have to acknowledge the fact that it is and then select ok and then proceed to sign out

I know that the script needs to placed in an accessible location with the correct permissions and that a GPO can be used to enforce this. The script part is what I need help with..

If anyone out there in the interwebs please help?

Environment OS: Windows 10 AD not in use. Novell system used.

James Westgate
  • 11,306
  • 8
  • 61
  • 68
sonic
  • 1
  • 1
    Welcome to Stack Overflow. Please take the [tour](https://stackoverflow.com/tour) and also read [How to Ask](https://stackoverflow.com/questions/how-to-ask). Stack Overflow is not a free script writing service. Your own research and code attempts are expected. Edit the question to include your code in a [Minimal, Complete, and Verifiable](https://stackoverflow.com/help/mcve) example. – Theo Nov 20 '18 at 13:08
  • try out this.https://stackoverflow.com/questions/101647/how-to-schedule-a-task-to-run-when-shutting-down-windows – Franco Pettigrosso Nov 20 '18 at 13:14

1 Answers1

0

After you checked out what Franco stated, you can try something like the following. But still need to figure out how to make it work properly:

$usbs = GET-WMIOBJECT win32_diskdrive | Where { $_.InterfaceType –eq ‘USB’ }
$devices = @()
foreach($usb in $usbs){
    $devices += $usb.Model + ". "
}
$input = [System.Windows.MessageBox]::Show("There are USB devices connected, $($devices | Out-String) Would you like to proceed logging off?","Warning","YesNoCancel","Error")
if($input -eq "Yes"){
    shutdown -L
}elseif($input -eq "No"){
    shutdown -A
}else{
    break    
}

You will need to find a way to make the user input visible before the logoff screen.

Bernard Moeskops
  • 1,203
  • 1
  • 12
  • 16