My script is running in O(n) time while checking multiple parameters; I'm seeking a way to get closer to O(1) time if possible. Please ignore the fact that I am utilizing excel; there are other portions of the script that are utilizing the methods. All suggestions are appreciated.
$rowMax = ($sheet.UsedRange.Rows).count
$count = 0
$countDelete = 0
#Declare the starting positions
$rowCompName,$colCompName = 1,3
#Checking Loop
for ($i=1; $i -le $rowMax-1; $i++){
$CompName = $sheet.Cells.Item($rowCompName+$i,$colCompName).text.ToUpper()
#Items Processed
$count++
#Removal of non-ND machines
if($CompName -eq ''){
continue
}
$CompName = $CompName.Substring(0,5)
if($CompName -ne "Name1" -and $CompName -ne "Name2" -and $CompName -ne "Name3" -and $CompName -ne "Name4") {
$returnsTrue = $sheet.Cells.Item($rowCompName+$i,$colCompName).EntireRow.Delete()
$rowsDeleted++
$i--
$rowMax--
$countDelete++
}
}
Aucun commentaire:
Enregistrer un commentaire