header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

XML objects used at powershell prompt vs in a script
Last Post 22 Jun 2008 08:27 PM by glnsize. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Anton1701User is Offline
New Member
New Member
Posts:13
Avatar

--
20 Jun 2008 06:46 PM  

Hello All,

At the powershell prompt I type these commands and receive this output as below:

****************************************************************************************************************

PS H:\> $PathToXmlDoc ="c:\codesets.xml"

PS H:\> [xml] $XMLDoc = (Get-Content $PathToXmlDoc )

PS H:\> $XMLDoc

codesets

-------------

codesets

PS H:\> $XMLDoc.codesets

previous   :  previous

finalnsr     :  finalnsr

***************************************************************************************************************

The output is as expectied

When I add these command to a ps1 script the output is black, and no error messages either.

Please help!

Thanks

Anton

halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:335
Avatar

--
20 Jun 2008 08:02 PM  

Incidentally, the parentheses are not required in line #2.  I see nothing inherently wrong in your code, though.  Works for me.  Perhaps run it with debug and/or verbose on.  Hmm, not too many good debugging articles on the net yet...I'd grab PowerShell Plus, PowerGUI, Admin Script Editor, PrimalScript, one of those sorts of tools which have some debugging tools built-in.

Would not hurt to read the help for start-psdebug.

  •  
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
glnsizeUser is Online
Basic Member
Basic Member
Posts:101

--
22 Jun 2008 08:27 PM  

Without seeing you actual script it's hard to see what could be the culprit. Having said that I would start with about_scopes...

PS H:\> $XMLDoc

is actually running...

PS H:\> $XMLDoc | out-default

Out-default targets the current scope. 

Remember scopes  Functions/scripts run under child scopes.  So even though the above is running, its not running under you console scope. Try putting a write-host, or write-verbose in your script to verify that the data is behaving it self.  Write-host always targets your console so the data will get back to you.

-Glenn

Feel free to criticize / correct me if I'm way off on this.  I'm only half way through Bruce's book :)

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer