We have a HR system that each night outputs a file with details of leavers to HR_LEAVERS.csv . We had an automated script that scanned through it, picked out the email addresses and sent just the addresses to a text file. Now I didn't write this script and I've no idea who set it up to begin with.
Powershell
$input_path=‘c:\leavers\HR_LEAVERS.csv’$output_file=‘c:\leavers\extracted_addresses.txt’$regex=‘\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b’select-string-Path$input_path-Pattern$regex-AllMatches|%{$_.Matches}|%{$_.Value}$output_fileI had a 2nd script that disabled the AD accounts based on the text file containing the user's email address - this bit I done.
Regex baffles me - I can see (I think) that it's looking for any combination of someone@somewhere.something and exporting it. However our HR...