Here is the "native" PowerShell way to do it. :)
[Reflection.Assembly]::LoadWithPartialName( 'Microsoft.VisualBasic' ) | Out-Null function InputBox( [string]$prompt, [string]$title, [string]$default ) { ( [string] ( [Microsoft.VisualBasic.Interaction]::InputBox( $prompt, $title, $default ) ) ).Trim() } function MsgBox( [string]$prompt, [string]$title, [int]$buttons ) { [int]([Microsoft.VisualBasic.Interaction]::MsgBox( $prompt, $buttons, $title ) ) } $vbOK = 1 $vbCancel = 2 $vbAbort = 3 $vbRetry = 4 $vbIgnore = 5 $vbYes = 6 $vbNo = 7 $vbOKOnly = 0 $vbOKCancel = 1 $vbAbortRetryIgnore = 2 $vbYesNoCancel = 3 $vbYesNo = 4 $vbRetryCancel = 5 $vbCritical = 16 $vbQuestion = 32 $vbExclamation = 48 $vbInformation = 64 $vbError = ( $vbOKOnly + $vbCritical ) ## this is mine and mine alone (not a standard value) $vbDefaultButton1 = 0 $vbDefaultButton2 = 256 $vbDefaultButton3 = 512 $vbApplicationModal = 0 $vbSystemModal = 4096 $vbMsgBoxSetForeground = 65536 $vbMsgBoxRight = 524288 $vbMsgBoxRtlReading = 1048576 From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of James Rankin Sent: Thursday, October 3, 2013 8:32 AM To: NTSysADM@lists.myitforum.com Subject: [NTSysADM] PowerShell (again) Is it possible to use PowerShell to display a message to a user and then log them out? My scenario is this:- Got to deliver three distinct desktops from one single image. The access to the desktops is controlled via AD group, so if you are in the Warehouse group, you get the Warehouse desktop. Now, for obvious reasons, I'd sooner have separated this by OU, because a user can only ever be in one OU, but the client doesn't want to do it this way. So if, for whatever reason, a user is erroneously added to two of the AD security groups, we want to halt the logon, display a message, and log the user out. Otherwise they will get a hotch-potch of settings which will look messy and behave in ways we can't predict, as two flavours of desktop try to override each other. The bit to check whether a user is in more than one of the three groups I can handle :-) It's the next bit giving me issues. I can't really find any reliable way to do the message box by Googling, and although I could do it with VBScript that feels like admitting defeat. Is there a good way to deliver a message box (just with an "OK" response) in PS? To log them out, I am assuming I could just call the Windows logoff.exe when the message box is gone. Unless there's a way to do logoffs native to PS? Thanks for the continued help with my battle to learn PS properly :-( Cheers, -- James Rankin Technical Consultant (ACA, CCA, MCTS) http://appsensebigot.blogspot.co.uk