### created arrays
$cell = [System.Collections.ArrayList]@()
$filepath = [System.Collections.ArrayList]@()
$index = $cell.IndexOf($_)
### this code pulls values from excel spread sheet as well as that files name and path
Get-ChildItem C:\UserS\chaos\OneDrive\Documents\working\srs\dynamic* | ForEach-Object {
$xl = New-Object -ComObject excel.application
$xl.Visible = $false
$woorkbookactive = $xl.Workbooks.Open($_.FullName)
$woorksheetactive = $woorkbookactive.Worksheets("Sheet1")
$RANGE = $woorksheetactive.Range("A4")
$cell.Add($RANGE.Value())
$filepath.Add($_.FullName)
$xl.Quit()
}
### the Above code produces these values
Selected Criteria: Enrolment Status: Left
Selected Criteria: Enrolment Status: Active
Selected Criteria: Enrolment Status: Active Permission Type: RESOURCE SCHEME
###
$cell
Start-Sleep -Seconds 2
switch -exact ($cell)
{
'Selected Criteria: Enrolment Status: Active Permission Type: RESOURCE SCHEME'{Write-Host "Found RS";Write-Host $index};#Rename-Item -Path $filepath[$index] -NewName "DynamicRS.xlsx";continue}
'Selected Criteria: Enrolment Status: Left'{Write-Host "Found Left";Write-Host $index};#Rename-Item -Path $filepath[$index] -NewName "DynamicLeft.xlsx";continue}
'Selected Criteria: Enrolment Status: Active' {Write-Host "Found Active";Write-Host $index};#Rename-Item -Path $filepath[$index] -NewName "DynamicActive.xlsx";continue}
default{write-host "no match found"}
}
I have tried with both regex and if statements however the values keep saying no match even though I can clearly see the matches
the output i received was this
no match found
no match found
no match found
I was expecting this
Found RS
found Left
Found Active
and sometimes it does detect them however the output it classes was wrong for example RS become Left and active Become Left.