![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | String expansion question Hi, I am looping through a xml construct and when displaying the $variable I see what the xmlelement contains. When I add this in a string (for expansion) powershell displays the type. foreach ($instance in $server.instance) { $instance #displays instance as expected $sqlagent="SQL Server Agent ($instance)" " #displays SQL Server Agent (System.Xml.XmlElement)" What is the trick here? Thanks, |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: String expansion question On Nov 7, 5:47 pm, gurbao <aud...@xxxxxx> wrote:
Hope this helps, - Oisin | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: String expansion question On Nov 8, 12:06 am, Oisin Grehan <ois...@xxxxxx> wrote:
It retuns an empty string. Other tips? Thanks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||
| Guest | Re: String expansion question > I am looping through a xml construct and when displaying the $variable
convert it to string: $variable.ToString() I can't test your code since it doesn't include all statments. Try to post A working example, it can help. ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: String expansion question On Nov 8, 9:03 am, Shay Levi <n...@xxxxxx> wrote:
Save the following as c:\temp\servers2.xml: <?xml version="1.0" encoding="utf-8"?> <servers> <server servername = "ws4762"> <instance instancename = "defaultinstance"></instance> <instance instancename = "s2000"></instance> </server> </servers> Then try this script: $servers = [xml](gc "c:\temp\servers2.xml") foreach ($server in $servers.servers.server) { foreach ($instance in $server.instance) { $instance # this displays the instancename "test $instance.ToString()" # here I miss something :-) } } Give it a go and enlighten me :-) Thanks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: String expansion question Here you go: $servers = [xml](gc "c:\temp\servers2.xml") foreach ($server in $servers.servers.server) { foreach ($instance in $server.instance) { #$instance.instancename $sqlagent="SQL Server Agent $($instance.instancename)" write-host $sqlagent } } defaultinstance SQL Server Agent defaultinstance s2000 SQL Server Agent s2000 ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||
| | #7 (permalink) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: String expansion question On Nov 8, 11:11 am, Shay Levi <n...@xxxxxx> wrote:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||