Why does this not display the results in the output window

Ask your Windows 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.
User avatar
daviesg6
Posts: 49
Joined: Thu Nov 21, 2013 12:36 pm

Why does this not display the results in the output window

Post by daviesg6 » Wed Nov 19, 2014 7:50 am

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 12:39 pm, edited 1 time in total.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Nov 19, 2014 11:04 am

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
Joined: Thu Nov 21, 2013 12:36 pm

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

Post by daviesg6 » Wed Nov 19, 2014 11:16 am

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.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Nov 19, 2014 11:35 am

How is it going to display if you are writing it to a file?

User avatar
daviesg6
Posts: 49
Joined: Thu Nov 21, 2013 12:36 pm

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

Post by daviesg6 » Wed Nov 19, 2014 12:38 pm

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.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Nov 19, 2014 4:41 pm

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
Joined: Thu Nov 21, 2013 12:36 pm

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

Post by daviesg6 » Thu Nov 20, 2014 7:32 am

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

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Nov 20, 2014 12:41 pm

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
Joined: Thu Nov 21, 2013 12:36 pm

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

Post by daviesg6 » Thu Nov 20, 2014 1:06 pm

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.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Nov 20, 2014 1:09 pm

For backgriyund on how to use Controls to build useful interfaces with Windows Forms start here: http://www.sapien.com/blog/topics/user- ... istrators/

Locked