It's Friday and my brain is focusing more on the weekend than work, so I ask your help, oh PowerShell community:
I've been tasked with converting our old VB new user script to Powershell, the input of which is a CSV that HR sends us on a daily basis. On rare occasion they include someone who already exists as a user, and I'd like to write a function to check the CSV for that and remove that line in the CSV before continuing processing. So far I have the 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 already exists!" } } }
But being said Friday, I can't figure out how to remove the "offending" line from the CSV and save it.