Why does this not display the results in the output window

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 9 years and 3 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.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Why does this not display the results in the output wind

Post by jvierra »

daviesg6 wrote:if out-string does nothing, why did you tell me in one of my first posts last year, to use this to get the output displayed in the text box? Why does it work on EVERY other script and GUI? If I am doing something wrong how about telling me how to fix it rather than just telling me something that works everywhere else is the cause of the issue and giving no indication of what is needed.
I do not think anyone has ever told you that OUt-String writes ti a control.

If we have a control we can assign a string to it.

$textbox1.Text='Hello'


If we have an object we cannot successfully assign the object to the control with much useful success.

$textbox1.Text=Get-Process

Try it to see what I am posting about.

At a PowerShell prompt we would use a formatter to get useful output:

$textbox1.Text=Get-Process |Format-List

But this won't work in a control. Try it to see what you get:

So we convert the formatter results to printable results:


$textbox1.Text=Get-Process |Format-List | Out-String

Try that to see what I mean.

Here is a demo project you can play with to learn how this control works.
Attachments
Demo-SimpleAssign.pff
(4.89 KiB) Downloaded 189 times
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Why does this not display the results in the output wind

Post by daviesg6 »

ok, I get you're saying this shouldn't work, but it does on the other parts of the script, so I hit the Search ID button, this is told to Out-string $Results.Focus() and it displays on the screen, in the window I have designated as the results window. The same goes for the Search Name button, enter a users name, hit the button and Out-string $Results.Focus() magically makes the output appear. There are no other bits of code telling this to put the output anywhere, this is it as far as the results are concerned. The query runs and the results are piped out to the code you are not happy with. This has worked on every GUI I have created, the same as changing it to Out-File h:\results.txt works and created a text file on my H drive containing the results I want.
I am having problems understanding why you say this does not work when clearly it does, apart from in this instance, and just changing the out-string to out-file works
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Why does this not display the results in the output wind

Post by jvierra »

I am sorry . I left you can example of how to write output to a textbox. I have no idea what you are taking about iwht the $results.focus().

Where do you see an example of this in any documentation? I have worked with Windows forms for 20 yeaes and have never heard of what you are trying to say.

Can you post an example PFF or PSF with this working as you say.
Last edited by jvierra on Thu Nov 20, 2014 6:08 pm, edited 1 time in total.
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Why does this not display the results in the output wind

Post by daviesg6 »

This is in a PrimalForms GUI, so standard powershell code is not always in play
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Why does this not display the results in the output wind

Post by daviesg6 »

here is the full script, GUI and all
PowerShell Code
Double-click the code block to select all.
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 11/11/2014 3:32 PM
# Generated By: gdavies
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$SDQueryForm = New-Object System.Windows.Forms.Form
$Info = New-Object System.Windows.Forms.Label
$BULogo = New-Object System.Windows.Forms.Label
$LastLogonLabel = New-Object System.Windows.Forms.Label
$LastLogonSurround = New-Object System.Windows.Forms.Label
$ExitButton = New-Object System.Windows.Forms.Button
$ExitButtonSurround = New-Object System.Windows.Forms.Label
$NameSearchButton = New-Object System.Windows.Forms.Button
$NameSearchButtonSurround = New-Object System.Windows.Forms.Label
$NameLabel = New-Object System.Windows.Forms.Label
$NameLabelSurround = New-Object System.Windows.Forms.Label
$IDSearchButton = New-Object System.Windows.Forms.Button
$ButtonSurround = New-Object System.Windows.Forms.Label
$EntryBox = New-Object System.Windows.Forms.TextBox
$EntryBoxSurround = New-Object System.Windows.Forms.Label
$IDLabel = New-Object System.Windows.Forms.Label
$IDLabelSurround = New-Object System.Windows.Forms.Label
$Results = New-Object System.Windows.Forms.TextBox
$ResultsSurrond = New-Object System.Windows.Forms.Label
$Instructions = New-Object System.Windows.Forms.Label
$InstructionsSurround = New-Object System.Windows.Forms.Label
$toolTip1 = New-Object System.Windows.Forms.ToolTip
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$LastLogonButton = New-Object System.Windows.Forms.Button
$LastLogonButtonSurround = New-Object System.Windows.Forms.Label
#endregion Generated Form Objects

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$NameSearchButton_OnClick= 

{ 
$results.Text=Get-ADUser -Filter "DisplayName -eq '$($EntryBox.text)'" -Properties DisplayName, sAMAccountName, mail, extensionattribute5, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | select givenName, surname, DisplayName, sAMAccountName, mail, extensionattribute5, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | Out-String
    $results.Focus()
}

$LoadMiodule= 
{
import-module activedirectory
set-location ad:
}

$IDSearchButton_OnClick= 
{
$results.Text=Get-ADUser -Filter "sAMAccountName -eq '$($EntryBox.text)'" -Properties DisplayName, sAMAccountName, mail, extensionattribute5, msExchHomeServerName, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | select givenName, surname, DisplayName, sAMAccountName, mail, extensionattribute5, msExchHomeServerName, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | Out-String
    $results.Focus()
}

$LastLogonButton_OnClick= 
{
$results.Text=$logons=@()
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().DomainControllers |
    ForEach{
        $logonInt=(Get-Aduser -Filter "sAMAccountName -eq '$($EntryBox.text)'" -server $_.Name -properties lastlogon).lastlogon
        $logons+=[datetime]::FromFileTime($logonInt)
    }

$newestLogon=($logons| Measure-Object -Max).Maximum 
$newestLogon | Out-string $results.Focus()
}

$ExitButton_OnClick= 
{
$SDQueryForm.Close()
}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
	$SDQueryForm.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code

$SDQueryForm.AutoScaleMode = 0
$SDQueryForm.BackColor = [System.Drawing.Color]::FromArgb(255,90,110,205)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 691
$System_Drawing_Size.Width = 984
$SDQueryForm.ClientSize = $System_Drawing_Size
$SDQueryForm.DataBindings.DefaultDataSourceUpdateMode = 0
$SDQueryForm.MaximizeBox = $False
$SDQueryForm.MinimizeBox = $False
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 728
$System_Drawing_Size.Width = 1150
$SDQueryForm.MaximumSize = $System_Drawing_Size
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 678
$System_Drawing_Size.Width = 1150
$SDQueryForm.MinimumSize = $System_Drawing_Size
$SDQueryForm.Name = "SDQueryForm"
$SDQueryForm.ShowIcon = $False
$SDQueryForm.SizeGripStyle = 2
$SDQueryForm.StartPosition = 1
$SDQueryForm.Text = "Service Desk AD Queries"
$SDQueryForm.add_Load($LoadMiodule)

$Info.DataBindings.DefaultDataSourceUpdateMode = 0
$Info.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",6,0,3,0)
$Info.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 205
$System_Drawing_Point.Y = 680
$Info.Location = $System_Drawing_Point
$Info.Name = "Info"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 10
$System_Drawing_Size.Width = 798
$Info.Size = $System_Drawing_Size
$Info.TabIndex = 20
$Info.Text = "Developed by Gareth Davies - Bellevue university Server Administrator"
$Info.TextAlign = 512

$SDQueryForm.Controls.Add($Info)

$BULogo.BackColor = [System.Drawing.Color]::FromArgb(255,248,248,255)
$BULogo.DataBindings.DefaultDataSourceUpdateMode = 0
$BULogo.Image = [System.Drawing.Image]::FromFile('S:\bulogo.jpg')
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 613
$BULogo.Location = $System_Drawing_Point
$BULogo.Name = "BULogo"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 70
$System_Drawing_Size.Width = 180
$BULogo.Size = $System_Drawing_Size
$BULogo.TabIndex = 19

$SDQueryForm.Controls.Add($BULogo)

$LastLogonLabel.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$LastLogonLabel.BorderStyle = 2
$LastLogonLabel.DataBindings.DefaultDataSourceUpdateMode = 0
$LastLogonLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 210
$LastLogonLabel.Location = $System_Drawing_Point
$LastLogonLabel.Name = "label12"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$LastLogonLabel.Size = $System_Drawing_Size
$LastLogonLabel.TabIndex = 18
$LastLogonLabel.Text = "Last Logon"
$LastLogonLabel.TextAlign = 32

$SDQueryForm.Controls.Add($LastLogonLabel)

$LastLogonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$LastLogonSurround.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 207
$LastLogonSurround.Location = $System_Drawing_Point
$LastLogonSurround.Name = "NameLabelSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$LastLogonSurround.Size = $System_Drawing_Size
$LastLogonSurround.TabIndex = 12

$SDQueryForm.Controls.Add($LastLogonSurround)

$ExitButton.BackColor = [System.Drawing.Color]::FromArgb(255,255,99,71)

$ExitButton.DataBindings.DefaultDataSourceUpdateMode = 0
$ExitButton.FlatStyle = 1
$ExitButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$ExitButton.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$ExitButton.Image = [System.Drawing.Image]::FromFile('S:\exit.jpg')
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1024
$System_Drawing_Point.Y = 628
$ExitButton.Location = $System_Drawing_Point
$ExitButton.Name = "ExitButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$ExitButton.Size = $System_Drawing_Size
$ExitButton.TabIndex = 17
$ExitButton.UseVisualStyleBackColor = $False
$ExitButton.add_Click($ExitButton_OnClick)

$SDQueryForm.Controls.Add($ExitButton)

$ExitButtonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$ExitButtonSurround.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1021
$System_Drawing_Point.Y = 625
$ExitButtonSurround.Location = $System_Drawing_Point
$ExitButtonSurround.Name = "ExitButtonSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$ExitButtonSurround.Size = $System_Drawing_Size
$ExitButtonSurround.TabIndex = 16

$SDQueryForm.Controls.Add($ExitButtonSurround)

$NameSearchButton.BackColor = [System.Drawing.Color]::FromArgb(255,90,110,205)

$NameSearchButton.DataBindings.DefaultDataSourceUpdateMode = 0
$NameSearchButton.FlatStyle = 1
$NameSearchButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$NameSearchButton.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1024
$System_Drawing_Point.Y = 155
$NameSearchButton.Location = $System_Drawing_Point
$NameSearchButton.Name = "NameSearchButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$NameSearchButton.Size = $System_Drawing_Size
$NameSearchButton.TabIndex = 15
$NameSearchButton.Text = "Name Search"
$NameSearchButton.UseVisualStyleBackColor = $False
$NameSearchButton.add_Click($NameSearchButton_OnClick)

$SDQueryForm.Controls.Add($NameSearchButton)

$NameSearchButtonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$NameSearchButtonSurround.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1021
$System_Drawing_Point.Y = 152
$NameSearchButtonSurround.Location = $System_Drawing_Point
$NameSearchButtonSurround.Name = "NameSearchButtonSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$NameSearchButtonSurround.Size = $System_Drawing_Size
$NameSearchButtonSurround.TabIndex = 14

$SDQueryForm.Controls.Add($NameSearchButtonSurround)

$LastLogonButton.BackColor = [System.Drawing.Color]::FromArgb(255,90,110,205)

$LastLogonButton.DataBindings.DefaultDataSourceUpdateMode = 0
$LastLogonButton.FlatStyle = 1
$LastLogonButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$LastLogonButton.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1024
$System_Drawing_Point.Y = 210
$LastLogonButton.Location = $System_Drawing_Point
$LastLogonButton.Name = "LastLogonButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$LastLogonButton.Size = $System_Drawing_Size
$LastLogonButton.TabIndex = 15
$LastLogonButton.Text = "Last Logon Search"
$LastLogonButton.UseVisualStyleBackColor = $False
$LastLogonButton.add_Click($LastLogonButton_OnClick)

$SDQueryForm.Controls.Add($LastLogonButton)

$LastLogonButtonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$LastLogonButtonSurround.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1021
$System_Drawing_Point.Y = 207
$LastLogonButtonSurround.Location = $System_Drawing_Point
$LastLogonButtonSurround.Name = "LastLogonButtonSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$LastLogonButtonSurround.Size = $System_Drawing_Size
$LastLogonButtonSurround.TabIndex = 14

$SDQueryForm.Controls.Add($LastLogonButtonSurround)


$NameLabel.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$NameLabel.BorderStyle = 2
$NameLabel.DataBindings.DefaultDataSourceUpdateMode = 0
$NameLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 155
$NameLabel.Location = $System_Drawing_Point
$NameLabel.Name = "NameLabel"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$NameLabel.Size = $System_Drawing_Size
$NameLabel.TabIndex = 13
$NameLabel.Text = "Full Name"
$NameLabel.TextAlign = 32

$SDQueryForm.Controls.Add($NameLabel)

$NameLabelSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$NameLabelSurround.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 152
$NameLabelSurround.Location = $System_Drawing_Point
$NameLabelSurround.Name = "NameLabelSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$NameLabelSurround.Size = $System_Drawing_Size
$NameLabelSurround.TabIndex = 12

$SDQueryForm.Controls.Add($NameLabelSurround)

$IDSearchButton.BackColor = [System.Drawing.Color]::FromArgb(255,90,110,205)

$IDSearchButton.DataBindings.DefaultDataSourceUpdateMode = 0
$IDSearchButton.FlatStyle = 1
$IDSearchButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)
$IDSearchButton.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1024
$System_Drawing_Point.Y = 100
$IDSearchButton.Location = $System_Drawing_Point
$IDSearchButton.Name = "IDSearchButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$IDSearchButton.Size = $System_Drawing_Size
$IDSearchButton.TabIndex = 11
$IDSearchButton.Text = "ID Search"
$IDSearchButton.UseVisualStyleBackColor = $False
$IDSearchButton.add_Click($IDSearchButton_OnClick)

$SDQueryForm.Controls.Add($IDSearchButton)

$ButtonSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$ButtonSurround.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1021
$System_Drawing_Point.Y = 97
$ButtonSurround.Location = $System_Drawing_Point
$ButtonSurround.Name = "ButtonSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$ButtonSurround.Size = $System_Drawing_Size
$ButtonSurround.TabIndex = 10

$SDQueryForm.Controls.Add($ButtonSurround)

$EntryBox.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 133
$System_Drawing_Point.Y = 155
$EntryBox.Location = $System_Drawing_Point
$EntryBox.Multiline = $True
$EntryBox.Name = "EntryBox"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 870
$EntryBox.Size = $System_Drawing_Size
$EntryBox.TabIndex = 9
$EntryBox.TextAlign = 2

$SDQueryForm.Controls.Add($EntryBox)

$EntryBoxSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$EntryBoxSurround.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 130
$System_Drawing_Point.Y = 152
$EntryBoxSurround.Location = $System_Drawing_Point
$EntryBoxSurround.Name = "EntryBoxSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 876
$EntryBoxSurround.Size = $System_Drawing_Size
$EntryBoxSurround.TabIndex = 8

$SDQueryForm.Controls.Add($EntryBoxSurround)

$IDLabel.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$IDLabel.BorderStyle = 2
$IDLabel.DataBindings.DefaultDataSourceUpdateMode = 0
$IDLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 100
$IDLabel.Location = $System_Drawing_Point
$IDLabel.Name = "IDLabel"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 100
$IDLabel.Size = $System_Drawing_Size
$IDLabel.TabIndex = 7
$IDLabel.Text = "User or Student ID"
$IDLabel.TextAlign = 32

$SDQueryForm.Controls.Add($IDLabel)

$IDLabelSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$IDLabelSurround.DataBindings.DefaultDataSourceUpdateMode = 0
$IDLabelSurround.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 97
$IDLabelSurround.Location = $System_Drawing_Point
$IDLabelSurround.Name = "IDLabelSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 46
$System_Drawing_Size.Width = 106
$IDLabelSurround.Size = $System_Drawing_Size
$IDLabelSurround.TabIndex = 6
$IDLabelSurround.TextAlign = 32

$SDQueryForm.Controls.Add($IDLabelSurround)

$Results.BackColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$Results.DataBindings.DefaultDataSourceUpdateMode = 0
$Results.Font = New-Object System.Drawing.Font("Lucida Console",8.25,0,3,0)
$Results.ForeColor = [System.Drawing.Color]::FromArgb(255,128,255,128)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 263
$Results.Location = $System_Drawing_Point
$Results.Multiline = $True
$Results.Name = "Results"
$Results.ReadOnly = $True
$Results.ScrollBars = 2
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 340
$System_Drawing_Size.Width = 1114
$Results.Size = $System_Drawing_Size
$Results.TabIndex = 5

$SDQueryForm.Controls.Add($Results)

$ResultsSurrond.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$ResultsSurrond.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 260
$ResultsSurrond.Location = $System_Drawing_Point
$ResultsSurrond.Name = "ResultsSurrond"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 346
$System_Drawing_Size.Width = 1120
$ResultsSurrond.Size = $System_Drawing_Size
$ResultsSurrond.TabIndex = 4

$SDQueryForm.Controls.Add($ResultsSurrond)

$Instructions.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$Instructions.BorderStyle = 2
$Instructions.DataBindings.DefaultDataSourceUpdateMode = 0
$Instructions.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 10
$Instructions.Location = $System_Drawing_Point
$Instructions.Name = "Instructions"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 70
$System_Drawing_Size.Width = 1114
$Instructions.Size = $System_Drawing_Size
$Instructions.TabIndex = 2
$Instructions.Text = "Enter the User, student ID or the FULL NAME in the box below and hit the relevant search button. You will see the details of the account, including the First name, Last name, Email address - student email is listed as extensionattribute5, date the password was last set, if the password has expired and if ActiveSync is disabled - This will appear as msExchOmaAdminWirelessEnable, if the value is 4 it is disabled, no value means it is enabled. The Last Logon search will display the last time the user account was authenticated by a DC."
$Instructions.TextAlign = 32

$SDQueryForm.Controls.Add($Instructions)

$InstructionsSurround.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$InstructionsSurround.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 7
$InstructionsSurround.Location = $System_Drawing_Point
$InstructionsSurround.Name = "InstructionsSurround"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 76
$System_Drawing_Size.Width = 1120
$InstructionsSurround.Size = $System_Drawing_Size
$InstructionsSurround.TabIndex = 1
$InstructionsSurround.Text = "label2"

$SDQueryForm.Controls.Add($InstructionsSurround)

$toolTip1.IsBalloon = $False
$tooltip1.SetToolTip($EntryBox, “Enter the user/student ID or the persons FULL NAME. Part names will not work, just first or last name will not work.”)
$tooltip1.SetToolTip($IDSearchButton, “Click here to search for User or student ID details.”)
$tooltip1.SetToolTip($NameSearchButton, “Click here to search for User or student name details.”)
$tooltip1.SetToolTip($Results, “Search results will appear here. If no data is displayed you will need to check the ID or name you searched for.”)
$tooltip1.SetToolTip($ExitButton, “Click to Close the app.”)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $SDQueryForm.WindowState
#Init the OnLoad event to correct the initial state of the form
$SDQueryForm.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$SDQueryForm.ShowDialog()| Out-Null

} #End Function

#Call the Function
# add a helper
$showWindowAsync = Add-Type –memberDefinition @” 
[DllImport("user32.dll")] 
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); 
“@ -name “Win32ShowWindowAsync” -namespace Win32Functions –passThru 

function Show-PowerShell() 
{
      [void]$showWindowAsync::ShowWindowAsync((Get-Process –id $pid).MainWindowHandle, 10) 
} 

function Hide-PowerShell() 
{
     [void]$showWindowAsync::ShowWindowAsync((Get-Process –id $pid).MainWindowHandle, 2) 
     } 
Hide-PowerShell
GenerateForm
Lines 48 to 51 are what is behind one button, this works and displays in the output window called $results
Lines 60 to 63 are the code executed when another button is clicked, this works and displays the results in the same output window as the first button.

Both of these use Out-string $results.Focus() as the command to output to this location.
Lines 66 to 76 show the code behind the third button, again this is told to display the results in the same location using the exact same code, this fails. It clears any previously returned results from the output window but does NOT display the results obtained when the script is executed.

All 3 use the same code to point the output to the same location, 2 work, the third clears the window but does not populate it with new data.
Changing the code in the third button to Out-host displays the results in the native powershell window, but this is not acceptable as the people using this tool are NOT to have easy access to the command line. Changing it to out-file exports the results to the location and file specified. Out-printer prints the results to my default printer, so clearly the script works and gets what I want, it even sends it to anywhere I can tell it APART from the one location I want, which is the same place as the other commands have no issue sending the results to.

So before telling me Out-string $results.Focus() does nothing and is s syntax error please test the code above so you can see it WORKS everywhere apart from this one place. Out-string tells it to use the output location specified at the start of the code block, the .Focus() highlights the results so the service desk tech can just hit ctrl+c and copy the results into the ticket they are creating. Removing this bit of code makes no difference to the outcome for the third button, removing the entire pipe makes no changes either.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Why does this not display the results in the output wind

Post by jvierra »

I need you to upload the PFF or PFS file. It is not possible to work easily with a large file like the one you are posting.

Even so I cannot wee any place in the file that successfully uses Out-String to automatically populate a field.

As I posted before, what you are claiming is not possible and, unless you can show me a simple example of Out-String setting the text value of a textbox, you will have to go back and do this the way I showed you earlier.

$textbox1.Text = <something that results in a string value or array of sting values>
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Why does this not display the results in the output wind

Post by daviesg6 »

I do not have the pff file, I deleted it in error, I do have other ones, they use the same code and they all work, your suggested format IS what I use, the start of the code block details the textbox, it is then followed by the code I want executed and ends with the out-string, the code in question uses this as well, as shown every time I have posted it, here it is again[
powershell]$results.Text=$logons=@()
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().DomainControllers |
ForEach{
$logonInt=(Get-Aduser -Filter "sAMAccountName -eq '$($EntryBox.text)'" -server $_.Name -properties lastlogon).lastlogon
$logons+=[datetime]::FromFileTime($logonInt)
}

$newestLogon=($logons| Measure-Object -Max).Maximum
$newestLogon | Out-string $results.Focus()[/powershell]

The thing is, the pff file does not contain the code in question, it is just the GUI build, the code I am having issues with has to be entered using ISE or another editor so I fail to see what this will achieve, plus every time I try to post a file or image all it displays is the url or path.
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: Why does this not display the results in the output wind

Post by daviesg6 »

here is a much smaller file, this uses one of the scripts that works, as in it displays in the output text box, the element names have been left as the default ones used by primal forms. This version uses the same text box for both input and output but the code is the same, it still uses the out-string $textBox1.Focus() pipeline
PowerShell Code
Double-click the code block to select all.
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 11/21/2014 12:40 PM
# Generated By: gdavies
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$button1 = New-Object System.Windows.Forms.Button
$textBox1 = New-Object System.Windows.Forms.TextBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button1_OnClick= {$textBox1.Text=Get-ADUser -Filter "sAMAccountName -eq '$($TextBox1.text)'" -Properties DisplayName, sAMAccountName, mail, extensionattribute5, msExchHomeServerName, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | select givenName, surname, DisplayName, sAMAccountName, mail, extensionattribute5, msExchHomeServerName, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | Out-String
    $textBox1.Focus()}

$loadmodule= {import-module activedirectory
set-location ad:}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
	$form1.WindowState = $InitialFormWindowState}
#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 643
$System_Drawing_Size.Width = 730
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Primal Form"
$form1.add_Load($loadmodule)

$button1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 400
$System_Drawing_Point.Y = 50
$button1.Location = $System_Drawing_Point
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 75
$button1.Size = $System_Drawing_Size
$button1.TabIndex = 2
$button1.Text = "button1"
$button1.UseVisualStyleBackColor = $True
$button1.add_Click($button1_OnClick)

$form1.Controls.Add($button1)

$textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 40
$System_Drawing_Point.Y = 164
$textBox1.Location = $System_Drawing_Point
$textBox1.Multiline = $True
$textBox1.Name = "textBox1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 200
$System_Drawing_Size.Width = 619
$textBox1.Size = $System_Drawing_Size
$textBox1.TabIndex = 0

$form1.Controls.Add($textBox1)
#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Why does this not display the results in the output wind

Post by jvierra »

I do not understand what the last post is supposed to show. I shows only a simple assignent to a textbox.
PowerShell Code
Double-click the code block to select all.
$button1_OnClick={
    $textBox1.Text=Get-ADUser -Filter "sAMAccountName -eq '$($TextBox1.text)'" -Properties DisplayName, sAMAccountName, mail, extensionattribute5, msExchHomeServerName, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | select givenName, surname, DisplayName, sAMAccountName, mail, extensionattribute5, msExchHomeServerName, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable, whenCreated | Out-String    
    $textBox1.Focus()
}
The last line is pointless:
$textBox1.Focus()
it does nothing useful.

There i sno place in the coed you have posted showing how Out-String can set a value all by itself just because it appears on a line with setfocus.

You must assign the "Text" property of the control.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Why does this not display the results in the output wind

Post by jvierra »

I posted the following code to show how toget themax last logon time.
PowerShell Code
Double-click the code block to select all.
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().DomainControllers |
    ForEach{
        $logonInt=(Get-Aduser -Filter "sAMAccountName -eq '$($EntryBox.text)'" -server $_.Name -properties lastlogon).lastlogon
        $logons+=[datetime]::FromFileTime($logonInt)
    }
 
$newestLogon=($logons| Measure-Object -Max).Maximum
To make this work you need to assign it to something:

If you want it in a textbox assign it to teh Text property:

$textbox1.Text=$newestLogon

Just typing Out-String accomplishes nothing.

If you take the time to read the blog poss on designing forms you would start to understand how thisworks. I know it is very confusing for people who are not trained in rogramming or scripting but it is learnable.
This topic is 9 years and 3 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.
Locked