I am trying to open an excel file within power shell. Here is the code i am using
$excel
=New-Object-com excel.application
$excel
.Visible=$True
$excelfile
="C:\Users\adm_kmccallion\Desktop\AssetInventory.xlsx"
$sheet
='Test'
$ou
="ctnet.com/Eton"
#$ExcelWorkbook = $Excel.Workbooks.Open($ExcelFile, 2, $True)
$ExcelWorkbook
=$Excel.workbooks.open("C:\Users\adm_kmccallion\Desktop\AssetInventory.xlsx")
$ExcelWorkSheet
=$Excel.Worksheets.Item($Sheet)
but i am getting the following error
Method invocation failed because [System.__ComObject] doesn't contain a method named 'open'.
At C:\Users\adm_kmccallion\Desktop\test.ps1:11 char:39
+ $ExcelWorkbook = $Excel.workbooks.open <<<< ("C:\Users\adm_kmccallion\Desktop\AssetInventory.xlsx")
+ CategoryInfo : InvalidOperation: (open:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Any idea why?