Q:

PS Script to get data from excel then remove permissions on shared folder

Im creating a simple script to remove user's permission on a shared drive folder.  I have the usernames and shared drive folders in an excel file.  Only 2 columns, 1 for path and the other one is the usernames. 
Here's what I've done with the script
$file = "C:\share\LanguagePack\testing.xlsx"
$SheetName = "Sheet1"
$objExcel = New-Object -ComObject Excel. Application
$objExcel. Visible = $false
$WorkBook = $objExcel. Workbooks. Open($file)
$WorkSheet = $WorkBook. Sheets. Item($SheetName)
$WorkSheetRange = $WorkSheet. UsedRange
$RowCount = $WorkSheetRange. Rows. Count
$ColumnCount = $WorkSheetRange. Columns. Count

for ($num2=1, $num2 -lt $RowCount, $num2++) {

    $output = $WorkSheet.cells. Item($num2, 1).text
    $output1 = $WorkSheet.cells. Item($num2, 2).text

    icacls $output /remove:g $output1 /t

}

but im getting 
Could not compare "1" to "3 3".  Error: "Cannot convert the "System. Object[]" 
value of type "System. Object[]" to type "System. Int32"." 
At C:\share\LanguagePack\Untitled1.ps1:26 char:6
+ for ($num2=1, $num2 -lt $RowCount, $num2++) {
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : ComparisonFailure
Any ideas or tips?  Thanks

A:

Try this:
$file = "C:\share\LanguagePack\testing.xlsx"
$SheetName = "Sheet1"
$objExcel = New-Object -ComObject Excel. Application
$objExcel. Visible = $false
$WorkBook = $objExcel. Workbooks. Open($file)
$WorkSheet = $WorkBook. Sheets. Item($SheetName)
$WorkSheetRange = $WorkSheet. UsedRange
$RowCount = $WorkSheetRange. Rows. Count
$ColumnCount = $WorkSheetRange. Columns. Count

for($row=1; $row -le $RowCount; $row++) {

    $output = $WorkSheet.cells. Item($row, 1).text
    $output1 = $WorkSheet.cells. Item($row, 2).text

    icacls $output /remove:g $output1 /t
}

