I have a very simple script that grabs the content from an XML file and returns it but is not working:
$DataFile = Get-ChildItem \\$Server\C$\ *.data -Name
[xml]$DataFileContent = Get-Content Microsoft.PowerShell.Core\FileSystem::\\$Server\C$\$DataFile
Write-Host $DataFileContent
This script is not returning any data on the Write-Host, but the following is returning the correct data:
$DataFile = Get-ChildItem \\$Server\C$\ *.data -Name
Get-Content Microsoft.PowerShell.Core\FileSystem::\\$Server\C$\$DataFile
Yes, the file is an xml file and the file exists. I'm sure I am missing something, but not sure what it is. Any help will be appreciated
You cannot use Write-Host here since you're trying to display an [xml] object. Try write-output instead.
If you require Write-Host, you would need to represent the object as a string beforehand or use a property that outputs a string. For example:
[xml]$x = Get-Content y.xml
Write-Host $x.InnerXml
This may be a good idea to use with write-output, as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With