Page 1 of 4

Why does this not display the results in the output window

Posted: Wed Nov 19, 2014 7:50 am
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()
}

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

Posted: Wed Nov 19, 2014 11:04 am
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"
      }
}

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

Posted: Wed Nov 19, 2014 11:16 am
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.

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

Posted: Wed Nov 19, 2014 11:35 am
by jvierra
How is it going to display if you are writing it to a file?

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

Posted: Wed Nov 19, 2014 12:38 pm
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.

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

Posted: Wed Nov 19, 2014 4:41 pm
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.

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

Posted: Thu Nov 20, 2014 7:32 am
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

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

Posted: Thu Nov 20, 2014 12:41 pm
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.

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

Posted: Thu Nov 20, 2014 1:06 pm
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.

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

Posted: Thu Nov 20, 2014 1:09 pm
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/