2

I am currently trying to read the metadata from an index server export with PowerShell to be able to tag a SharePoint document library with this information.

First I search all XML files in the current directory:

$XMLPaths = Get-ChildItem -Recurse -Filter *.xml

Afterwards I get data content from each XML file:

foreach($xmlFile in $xmlPaths) {
     [xml]$xmlData = Get-Content -LiteralPath $xmlFile.FullName
...
}

when executing the script I get the Error message "There is no object in the specified path, or it was filtered by the parameters "-Include" or "-Exclude".

Get-Content : Im angegebenen Pfad C:\Users\...\1 Correspondence ZK12\2017\20170623 - CUSTOMER INVOICING - Re_ 
[Ticket#2017061510027357] [Ticket#2017061610029362] Invoice 80000066607 AF assistance March 17.msg.xml 
ist kein Objekt vorhanden, oder es wurde durch die Parameter "-Include" oder "-Exclude" gefiltert.

Since this only occurs with .msg.xml-files, I assume it may be due to non-breaking space or similar chars in the filenames. Nevertheless, I am surprised that this information seems to be lost between the commands Get-ChildItem and Get-Content.

Any suggestions on how I could fix this problem?

Steven
  • 6,817
  • 1
  • 14
  • 14
heim0r
  • 21
  • 1
  • 2
    What happens if you add `-LiteralPath ` and switch `-File` to the Get-ChildItem cmdlet ? You also may need to add switch `-Force` to get items that otherwise can't be accessed by the user, such as hidden or system files. – Theo Apr 18 '21 at 18:18
  • It _may_ be related to [this question](https://stackoverflow.com/q/66227382/45375), though that `Get-Content` would behave this way with `-LiteralPath` is puzzling. – mklement0 Apr 18 '21 at 21:36
  • It could also be related to the path length (more then 260 characters?) – iRon Apr 19 '21 at 08:23
  • I would try `$xmlFile | Get-Content` which occasionally figures things out better, IMX. However, my guess is that either there's security blocking the file or the filenames are legitimately wrong in the input file. – Bacon Bits Apr 19 '21 at 11:11

0 Answers0