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?
Debugging console
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.
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.
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Debugging console
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:
Hope this helps!
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
Re: Debugging console
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
"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 ?
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
- $alarmHashTable
- Name Value
- ---- -----
- 3 {Major, Board#1, Alarm Proxy Set 4: Proxy lost.}
- 4 {Major, IPGroup#4, IP Group is temporarily blocked. }
- $AlarmhashTable.GetType()
- IsPublic IsSerial Name BaseType
- -------- -------- ---- --------
- True True OrderedDictionary System.Object
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 ?
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Debugging console
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
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
Re: Debugging console
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
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
Re: Debugging console
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.
SAPIEN Technologies, Inc.
Re: Debugging console
We have yet to find a solution to the issue, but I will ask the dev team to revisit.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.