Use this forum to ask questions after your subscription maintenance expires or before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM. Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Product, version and build: PowerShell Studio 2016 v5.3.131
32 or 64 bit version of product: 64 bit
Operating system: Windows 10 Enterprise 1607
32 or 64 bit OS: 64 bit
Disclaimer: Complete Newb so please be kind.
I am trying to make the following POSH into a GUI that looks like the attached screenshot. Basically I need to prompt the user to enter a PIN that is minimum 6 numerical characters and max 20 and to make sure that their entries match in both text boxes or else tell them what the issue is (not matching and/or not meeting limit). I don't want the text to be masked so the user can see what they put in. This is for the purpose of setting BitLocker and Activating it with TPM and PIN. I am stuck in a loop that is crashing the form when I port it into PowerShell Studio 2016. Submit button should not appear until PIN matches criteria.
POSH:
Do
{
$Pin = Read-Host "PIN must be between 6-20 characters and contain only numbers. Please enter a PIN number"
} While (($Pin.Length -lt 6) -or ($Pin.Length -gt 20) -or ($Pin -match "\D"))
Do
{
$Pin2 = Read-Host "Please confirm the PIN number"
$Match = $Pin.CompareTo($Pin2)
If ($Match -ne 0)
{
Write-Host "PIN does not match"
$runagain = 'y'
}
else
{
$runagain = 'n'
}
} While ($runagain -eq 'y')
$SecPIN = ConvertTo-SecureString $pin -AsPlainText -Force
Add-BitLockerKeyProtector -MountPoint "C:" -Pin $SecPIN -TpmAndPinProtector
Backup-BitLockerKeyProtector -MountPoint "C:" -KeyProtectorId $Volume.KeyProtector[0].KeyProtectorId
What I have that is not really working in PowerShell Studio:
$ErrorProvider = New-Object System.Windows.Forms.ErrorProvider
$buttonSubmit.Enabled = $false
$textbox3_TextChanged = {
$buttonSubmit.Enabled = $textbox3.Text -ne ''
}
$buttonSUBMIT_Click = {
Do
{
$pin = $textbox2.Text
}
While (($pin.Length -lt 6) -or ($pin.Length -gt 20) -or ($pin -match "\D"))
Do
{
$pin2 = $textbox3.Text
$Match = $pin.CompareTo($Pin2)
If ($Match -ne 0)
{
$ErrorProvider.SetError($textbox2, "ONLY 20 CHARS ALLOWED!"); #InValid
Write-Host "Not Good"
$runagain = 'y'
}
else
{
$ErrorProvider.Clear() #Valid
Write-Host "Good"
$runagain = 'n'
$Form.Close()
}
}
While ($runagain -eq 'y')
}
$SecPIN = ConvertTo-SecureString $pin -AsPlainText -Force
Add-BitLockerKeyProtector -MountPoint "C:" -Pin $SecPIN -TpmAndPinProtector
Backup-BitLockerKeyProtector -MountPoint "C:" -KeyProtectorId $Volume.KeyProtector[0].KeyProtectorId
Looks like that worked in the sense that it does correctly prompt me to match the PINs or use the proper length, accordingly, but I am getting the following error after I click the Submit button. Do I need to specify the form name or something like that?
ERROR: You cannot call a method on a null-valued expression.
EnableBitLockerPIN.psf (29, 3): ERROR: At Line: 29 char: 3
ERROR: + $Form.Close()
ERROR: + ~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : InvokeMethodOnNull
ERROR:
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.