I have created a Powershell script to filter out a particular item in an coulmn . The script so far :
$file1 = "C:\Users\ab270510\Desktop\t.xlsx" # source's fullpath
$xl = new-object -c excel.application
$xl.displayAlerts = $false # don't prompt the user
$wb1 = $xl.workbooks.open($file1) # open target
$sh1 = $wb1.sheets.item('Sheet1') # sheet in workbook
$sh1.Select()
$sh1.Range("C1").Select()
$xlFilterValues = 7 # found in MS documentation
$filterList = “Jan”,”feb” # array
$xl.Selection.AutoFilter(2, $filterList ,$xlFilterValues)
$sh1.cells.Item.EntireColumn.AutoFit
$wb1.close($true) # close and save workbook
$xl.quit()
But the above code is giving error like : Exception calling "AutoFilter" with "3" argument(s): "AutoFilter method of Range class failed"
At line:1 char:25
+ $xl.Selection.AutoFilter <<<< (2, $filterList ,$xlFilterValues)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
Please help me to write a Powershell script that will filter out only "Jan" & "Feb" item from a particular coulmn of an excel file . Also suggest me how can I filter single or multiple item .