1

I'm not understanding something. I have a hashtable that contains locations of External Utilities

$ExtUtilities = @{}

Then later on I am adding them into the hash table from an XML document

$ExtUtilities.essclient = $XmlDoc.config.local.setup.external.utility.essclient
$ExtUtilities.lcm       = $XmlDoc.config.local.setup.external.utility.lcm
$ExtUtilities.sqlclient = $XmlDoc.config.local.setup.external.utility.sqlclient
$ExtUtilities.oraexport = $XmlDoc.config.local.setup.external.utility.oraexport

All is fine but I noticed that there are $nulls in the table for each entry and am not sure where they are coming from

Name                           Value
----                           -----
sqlclient                      {$null, $null, C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe, $null}
oraexport                      {$null, $null, $null, C:\app\client\epmadmin\product\12.1.0\client_1\BIN\exp.exe}
essclient                      {$null, C:\Oracle\Middleware\EPMSystem11R1\products\Essbase\EssbaseClient\bin\startMaxl.cmd, $null, $null}
lcm                            {C:\Oracle\Middleware\user_projects\Foundation1\bin\Utility.bat, $null, $null, $null}

The $nulls are messing with me running these commands as the CMD interpriter doesn't like the commands that have the leading $nulls.

Anyone can explain why there are $nulls there?

2
  • 1
    How do you expect us to tell without knowing what your XML document looks like, or how you load it into $XmlDoc? Commented Jan 9, 2017 at 17:20
  • I'm loading the XML by simply doing a get-content like so $xmlDoc = [xml](Get-Content -path Config.xml), but I think briantist has it right. Thanks for you reply. Commented Jan 9, 2017 at 17:24

1 Answer 1

3

Well it's hard to say without seeing your original XML, but likely it's because there are multiple matching elements; the result of of your $XmlDoc.config.local. etc. probably returns an array, and some of the values are $null.

You should be able to filter them out when you do the assignment, something like this:

$ExtUtilities.essclient = $XmlDoc.config.local.setup.external.utility.essclient | 
    Where-Object -FilterScript { $_ }

That will only assign the objects that resolve to $true.

If you really don't want an array, then also get only the first one:

$ExtUtilities.essclient = $XmlDoc.config.local.setup.external.utility.essclient | 
    Where-Object -FilterScript { $_ } |
    Select-Object -First 1
Sign up to request clarification or add additional context in comments.

1 Comment

Ah...That makes sense. I was starting to think it was something to do with the $xmlDoc but the pattern of $nulls per item kind of threw me off. I figured since I was asking for an explicit xml path that I wouldn't need to do any other filtering and such. Thanks for the reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.