Function to run conditional on CSV and delete line if true


it's friday , brain focusing more on weekend work, ask help, oh powershell community:

i've been tasked converting our old vb new user script powershell, input of csv hr sends on daily basis. on rare occasion include exists user, , i'd write function check csv , remove line in csv before continuing processing. far have following:

function clear-existing      {      param          (          [string]$path          )          $csv_input = import-csv -delimiter ',' $path -header @("empid","lastname","firstname","title","dept","status") | % ( $_.empid           foreach ($entry in $csv_input)              {              if (check-aduser $entry.empid -eq $true)                  {                  write-host "user $entry exists!"                  }              }      }

but being said friday, can't figure out how remove "offending" line csv , save it.



zarberg@gmail.com

it easy read in csv file.

$csv_input=import-csv $path -header empid,lastname,firstname,title,dept,status) |
     where-object{-not (get-aduser -filter "employeeid -eq '$($_.empid)'")}


¯\_(ツ)_/¯



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...