Build: v5.5.155
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17134.0
Hello,
I have a simple task that works in the Powershell ISE, oddly enough not in Powershell Studio.
I have a click event that takes a name from a textbox,
searches for this name via Get-ADUser and then builds a new object with only two properties.
These two properties should be added to the 'PSCUSTOMOBJECT' '$Result'.
If I use the click event to query new names with Get-ADuser again and again, all new entries should added in $Result again.
Unfortunately in my Powershell Studio the $Result array seems to be deleted over and over again, there is always only one entry in it, the last one.
In Powershell ISE every entry is added correctly and the array logically gets bigger.
Maybe I also have a thinking error?
Here is the code of Powershell-Studio
Code: Select all
$Result = @()
$btnGo_Click = {
$FindUsername=$txtUsername.Text
$User = (Get-ADUser -Identity $FindUsername)
$data = @{
SamAccountName = $User.SamAccountName
DistinguishedName = $User.DistinguishedName
}
$Result += New-Object -TypeName PSCUSTOMOBJECT -Property $data
#debug
Write-Host " : $($Result.SamAccountName)"
}
Output from Studio
Code: Select all
: Peter.Pan
: Bon.Jovi
*** PowerShell Script finished. ***
>> Execution time: 00:00:39
>> Script Ended
Now the same in Powershell ISE
Code: Select all
$Result=@()
while ($exit -eq 'false' )
{
$Input = Read-Host 'Input User Name to find or type "q" '
if ($Input -ne 'q'){
$User = (Get-ADUser -Identity $Input)
$data = @{
SamAccountName = $User.SamAccountName
DistinguishedName = $User.DistinguishedName
}
$Result += New-Object -TypeName PSCUSTOMOBJECT -Property $data
Write-host -ForegroundColor Yellow ": $($Result.SamAccountName)"
}else{
$exit = 'true'
}
}
Code: Select all
Input User Name to find or type "q" : peter.pan
: peter.pan
Input User Name to find or type "q" : bon.jovi
[b]peter.pan bon.jovi[/b]
I hope I made it clear what I meant.
Do you have any idea what that could be, so why does the variable "$Result" seem to be reset?
many thanks in advance