Code completion doesn't work as expected

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 3 years and 8 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.
chbwien
Posts: 6
Last visit: Thu Aug 24, 2023 4:18 am

Code completion doesn't work as expected

Post by chbwien »

If I use the following simple demo code:
  1. [xml]$xml = Get-Content 'inventory.xml'
  2. foreach ($node in $xml.DocumentElement.Childnodes)
  3. {
  4.     $myjuhu = $xml.CreateElement('juhu')
  5.     $myjuhu.innerText = 'juhu'
  6.     [void]$node.appendchild($myjuhu)
  7.     $node.removechild($myjuhu)
  8. }
  9. $xml.Save('inventory_out.xml')
I have no chance to get any help if I type $node.

If I do the same with the standard ISE, after the first run ISE knows the type of $node and it will offer me methods for $node.
2020-07-29 12_43_52-Windows PowerShell ISE.png
2020-07-29 12_43_52-Windows PowerShell ISE.png (65.65 KiB) Viewed 849 times
So what do I have to do, to get at least the same help from Powershell Studio?
User avatar
brittneyr
Site Admin
Posts: 1672
Last visit: Wed Apr 17, 2024 1:24 pm
Answers: 39
Been upvoted: 31 times

Re: Code completion doesn't work as expected

Post by brittneyr »

This is because it does not know what the type of $node is, therefore the editor does not know what information to provide via intellisense. As you casted the the result of Get-Content to xml, it was then recognized as xml and intellisense information was able to be provided. PowerShell Studio doesn't store information about the script after its run.

You may find the following helpful:
https://adamtheautomator.com/powershell-cast-object/
Brittney
SAPIEN Technologies, Inc.
This topic is 3 years and 8 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.