PowerShell Code
Double-click the code block to select all.$ComputerName = '192.168.1.51' $vercon = Test-Connection -ComputerName $ComputerName -Quiet -Count 1 if ($vercon -eq $false) {[System.Windows.Forms.MessageBox]::Show("$computername is not responding to a ping! Please verify machine is online.", "Verify Connection",0, 'Stop')} if ($ComputerName -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") { if ($credential -eq $null) {$credential = Get-Credential -Message "Please enter credentials to access $computername. You can enter your credentials assuming you're an administrator on $computername."} do something }else { do something else }When that is run as a PowerShell script or inside the PowerShell ISE the credential variable persists. Meaning that the first time I run it, I'm prompted for credentials. The second time the credential variable is not null, therefore it does not prompt me and moves into the else block.
When I put the same code into a form script, I'm prompted for credentials every time I click my button. It's acting like the credential variable is null every time. Is this normal?