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 4 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
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Why does this not display the results in the output window

Post by daviesg6 »

PowerShell Code
Double-click the code block to select all.
$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()
}
I have other buttons running different scripts using the same output window, they display fine. If I change it to
PowerShell Code
Double-click the code block to select all.
$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-file c:\temp\lastlogon.txt()
}
It creates a text file and populates it with the results I am looking for.
If I run this query, set to display on screen, I get no output and no errors. What am I missing?

For reference, here is the script behind one of the other buttons, this one works perfectly
PowerShell Code
Double-click the code block to select all.
$IDSearchButton_OnClick= 
{
$results.Text=Get-ADUser -Filter "sAMAccountName -eq '$($EntryBox.text)'" -Properties DisplayName, sAMAccountName, mail, lastlogondate, extensionattribute5, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable | Out-String
    $results.Focus()
}
Last edited by daviesg6 on Wed Nov 19, 2014 11:39 am, edited 1 time in total.
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 »

PowerShell Code
Double-click the code block to select all.
$IDSearchButton_OnClick= {
      $samName=$EntryBox.text
      if($userData=Get-ADUser -Filter "sAMAccountName -eq '$samName'" -Properties DisplayName, sAMAccountName, mail, lastlogondate, extensionattribute5, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable){
           $results.Text=$userData |   Format-List |  Out-String
      }else{
           $results.Text="User $samName NOT found"
      }
}
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 »

The code block you have edited was working, it was the first one,
PowerShell Code
Double-click the code block to select all.
$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()
}
that gives no results when directed to the output window.
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 »

How is it going to display if you are writing it to a file?
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 »

It isn't being written to a file, the last part of the code,
PowerShell Code
Double-click the code block to select all.
Out-String    $results.Focus()


tells it to display in the text box called results. As my question stated, if I changed this to write to a file it worked, but when it is set to display in the text window it gives nothing.
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:It isn't being written to a file, the last part of the code,
PowerShell Code
Double-click the code block to select all.
Out-String    $results.Focus()


tells it to display in the text box called results. As my question stated, if I changed this to write to a file it worked, but when it is set to display in the text window it gives nothing.
That does nothing. I cannot undrstand what you are trying to do. Why send it to a file and why just type Out-String $results.Focus()?

That is meaningless and a syntax error.

To get informaiton into a control you need to assign the controls value member or other settable member to the value you want to display or use.

$textbox1.Text-='Hello World'

That is how to assign a value to a textbox control. Just typeing Out-SString does nothing.
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 »

Look at the example I gave that works.
In primal forms out-string $vsriable.focus() is the code used to point the output to the form element used for output. I have 2 other buttons on the form that execute different scripts, both of these say out-string $Results.Focus() and both of them display the results on screen.
I have created multiple other forms using primal forms, and all scripts that are required to display the results on screen also use out-string $variable.Focus() where $variable is the name of the text window used as the display.
It works in EVERY instance apart from this one, I will post the entire script if you want, but it is hundreds of lines so not really the best way to demonstrate. Here is a part of the code used in the form, note it uses the code you are unhappy with, but it does exactly what it is supposed to do, it displays the results on the screen in the text box called $results.
Code
PowerShell Code
Double-click the code block to select all.
$results.Text=Get-ADUser -Filter "sAMAccountName -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()


The code works in every instance apart from this query I am having issues with.
Result
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 but the Out-String and focus do nothing. I do not know what you think is doing that but those lines are not assigning anything.

<control>.focus() moves the input focus to the specified counrol.

THe line Out-String does nothing.
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 »

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.
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 »

For backgriyund on how to use Controls to build useful interfaces with Windows Forms start here: http://www.sapien.com/blog/topics/user- ... istrators/
This topic is 9 years and 4 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