I've been using this script with no issues and all of the sudden, i'm getting a divide by zero error. the script is to update or change a couple of attributes and a colleague added the counter/status since we sometimes have hundreds of changes to make. I've been using powershell ise since going to Win11 as I was having issues with regular PS.
I tried pulling the data from a fresh csv file thinking that may have been the issue; no luck. Here is what I have:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -force
import-module Activedirectory
$Path = "C:\Users\cn116943\Input\ad_data_TN_IP_update.csv"
$CSV = import-csv $Path
$CRED = get-credential "Centene\a_cn116943"
#Counter for progress status
$counter = 0
$total = $CSV.count
foreach($row in $csv){
$counter++
Write-Progress -Activity "Processing: $row" -Status "$($counter) of $($total)" - PercentComplete (($counter/$total)*100)
if($row.action -eq 'update'){
set-aduser $row.user -credential $cred -replace @{ipPhone= "$($row.phone)"}
set-aduser $row.user -credential $cred -replace @{telephonenumber= "$($row.phone)"}
}
if($row.action -eq 'remove'){
set-aduser $row.user -credential $cred -Clear ipPhone
set-aduser $row.user -credential $cred -Clear telephonenumber