Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

XMLImport from Powershell Script

$
0
0

I have been trying to get XMLImport to work via a Powershell script so I can pull gpresult.xml files into Excel for reporting.  In the script I am getting errors. 

 

PS D:\GPO Backup> $directory = "D:\GPO Backup"
$folders = Get-ChildItem -Path $directory

foreach ($item in $folders)
    {
                       
        $objExcel = New-Object -ComObject Excel.Application 
        $wb = $objExcel.Workbooks.Add()
        $ws = $wb.Worksheets.Item(1)
        $objExcel.Visible = $True
        
        $N = $item.name.ToString()
        
        $Ov = "True"
        $Dest = "$wb.Range(A,1)"

        $Location = "D:\GPO Backup\" + $N + "\gpreport.xml"
        $F = $location.tostring()
        #$xml = "http://www.w3.org/2001/xmlschema"
        $map=$wb.XmlMaps.Add('http://www.w3.org/2001/xmlschema')

       
        $wb.xmlImport($F,[ref]$map,$Ov,$Dest)
        

        }
Exception calling "Add" with "1" argument(s): "XML Parse Error"
At line:20 char:9+         $map=$wb.XmlMaps.Add('http://www.w3.org/2001/xmlschema')+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : ComMethodTargetInvocation
Exception calling "XmlImport" with "4" argument(s): "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"
At line:23 char:9+         $wb.xmlImport($F,[ref]$map,$Ov,$Dest)+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : ComMethodTargetInvocation

The link to the original conversation is: http://social.technet.microsoft.com/Forums/scriptcenter/en-US/9baca1d9-e5cb-4883-afac-de9796a7e2e1/use-excel-xmlimport-in-powershell-script?forum=ITCG

It would appear I am not getting the arguments right for the import.

Thanks,

KMD


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>