Debugging console

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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 6 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.
User avatar
T2M_Mitch
Posts: 6
Last visit: Mon Jun 13, 2022 10:59 am

Debugging console

Post by T2M_Mitch »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: powershell studio 2017 5.4.145.0
32 or 64 bit version of product: 64
Operating system: windows 10
32 or 64 bit OS: 64

*** Please add details and screenshots as needed below. ***

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

I am working on a script and need to test different values in an array
I need to be able to change a change a value like this $myarray[0] = "someNewValue"

when I make this change in the debug console I get an echo back of the value I set , but it does not appear in the array

when I do this outside of PowerShell studio ( from a PowerShell prompt or in regular the windows ISE ) I get the expected result, ie the value changes, and can be displayed queried etc.
However, when I try to do this via the debug console, my value becomes empty ( not $null) and I am unable to perform the validation needed
is this a bug? what am I supposed to use to make changes to an array while debugging a script?
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Debugging console

Post by mxtrinidad »

In order to be able to update an array, you will need to change the PSObject type from [Array} to be [System.Collections.ArrayList].

See below sample:

Code: Select all

PS [40] > [System.Collections.ArrayList]$Seafood = "Tuna","Snapper","Banana","Grouper"
PS [41] >
PS [42] > $Seafood.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     ArrayList                                System.Object


PS [49] >
PS [51] > $Seafood
Tuna
Snapper
Banana
Grouper
PS [56] > $Seafood.remove("Banana")
PS [57] >
PS [58] > $Seafood
Tuna
Snapper
Grouper
PS [62] >
PS [63] > $Seafood += "Dorado"
PS [64] >
PS [65] > $Seafood
Tuna
Snapper
Grouper
Dorado
Hope this helps!
User avatar
T2M_Mitch
Posts: 6
Last visit: Mon Jun 13, 2022 10:59 am

Re: Debugging console

Post by T2M_Mitch »

actually I am not sure I follow you

Are you saying I have to "qualify" the object like this in my script or only when accessing it via debug console?

Also my array is actually a value in an ordered hashtable, and your suggestion still doesn't seem to work for me from the debug console .
in my hashtable I have a key and an array of values - I am trying to change the value of one of the elements in the array
  1.  
  2.  $alarmHashTable
  3.  
  4. Name                           Value
  5. ----                           -----
  6. 3                              {Major,    Board#1,      Alarm Proxy Set 4: Proxy lost.}
  7. 4                              {Major,    IPGroup#4,   IP Group is temporarily blocked. }
  8.  
  9.  
  10. $AlarmhashTable.GetType()
  11.  
  12. IsPublic IsSerial Name                                     BaseType
  13. -------- -------- ----                                     --------
  14. True     True     OrderedDictionary                        System.Object
  15.  
  16.  
"value" is an array and is what I am trying to change


As mentioned in my original post , I do not have to do this via he standard powershell CLI - can you explain why this behavior exists ?
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Debugging console

Post by mxtrinidad »

Apologies! In your post you mention about having issues with array objects and not hash table objects.
So, in this case you should work with Hash tables object methods which will include *.Add("Key", "Value") and *.Remove("Key").

I was able to use the Debug to test adding and remove on a Hash table.

To replace the array value, you'll have to remove and add the key back.
$hashtable.remove("Test")
$hsarrValue = "Volvo Dealer", "Jensen Beach", "Florida";
$hashtable.Add("Test", $hsarrValue);

or,

(I was able to do the line below in Debug Console after setting the variable "Add to Watch")
$HashTable.Add("Test6", ("Volvo Dealer","Jensen Beach","Florida"))

Let us know if it works.

FYI... To reorder the keys:
$hashtable.GetEnumerator() | sort -property name
User avatar
T2M_Mitch
Posts: 6
Last visit: Mon Jun 13, 2022 10:59 am

Re: Debugging console

Post by T2M_Mitch »

I will have a try

I guess what I am not understanding is the difference between the debug console and the command line / ISE debug interface ...

Can you point me To any good sapien docs that explain the debug console and reasoning behind this behavior
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Debugging console

Post by davidc »

This is a known issue where the variable assignments don't carry over via the Debug Console. The application is submitting the commands to PowerShell but for some reason it is not updating the runspace. I suspect there is a scoping issue within PowerShell when it sends over the commands.
David
SAPIEN Technologies, Inc.
User avatar
T2M_Mitch
Posts: 6
Last visit: Mon Jun 13, 2022 10:59 am

Re: Debugging console

Post by T2M_Mitch »

is it a known issue that is scheduled to be resolved?
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Debugging console

Post by davidc »

We have yet to find a solution to the issue, but I will ask the dev team to revisit.
David
SAPIEN Technologies, Inc.
This topic is 6 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.