Debugging console

Support for all customers who have purchased a SAPIEN PowerShell Studio product license. This forum does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
T2M_Mitch
Posts: 6
Joined: Mon Jul 24, 2017 1:58 pm

Debugging console

Post by T2M_Mitch » Mon Dec 04, 2017 12:21 pm

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
Site Admin
Posts: 45
Joined: Sun Mar 03, 2013 12:42 pm

Re: Debugging console

Post by mxtrinidad » Mon Dec 04, 2017 12:41 pm

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
Joined: Mon Jul 24, 2017 1:58 pm

Re: Debugging console

Post by T2M_Mitch » Mon Dec 04, 2017 2:47 pm

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.  
  3.  $alarmHashTable
  4.  
  5.  
  6.  
  7. Name                           Value
  8.  
  9. ----                           -----
  10.  
  11. 3                              {Major,    Board#1,      Alarm Proxy Set 4: Proxy lost.}
  12.  
  13. 4                              {Major,    IPGroup#4,   IP Group is temporarily blocked. }
  14.  
  15.  
  16.  
  17.  
  18.  
  19. $AlarmhashTable.GetType()
  20.  
  21.  
  22.  
  23. IsPublic IsSerial Name                                     BaseType
  24.  
  25. -------- -------- ----                                     --------
  26.  
  27. True     True     OrderedDictionary                        System.Object
  28.  
  29.  
  30.  
  31.  
"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
Site Admin
Posts: 45
Joined: Sun Mar 03, 2013 12:42 pm

Re: Debugging console

Post by mxtrinidad » Mon Dec 04, 2017 4:22 pm

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
Joined: Mon Jul 24, 2017 1:58 pm

Re: Debugging console

Post by T2M_Mitch » Mon Dec 04, 2017 8:11 pm

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: 4982
Joined: Thu Aug 18, 2011 4:56 am

Re: Debugging console

Post by davidc » Tue Dec 05, 2017 10:22 am

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
Joined: Mon Jul 24, 2017 1:58 pm

Re: Debugging console

Post by T2M_Mitch » Tue Dec 05, 2017 12:05 pm

is it a known issue that is scheduled to be resolved?

User avatar
davidc
Posts: 4982
Joined: Thu Aug 18, 2011 4:56 am

Re: Debugging console

Post by davidc » Tue Dec 05, 2017 2:08 pm

We have yet to find a solution to the issue, but I will ask the dev team to revisit.
David
SAPIEN Technologies, Inc.