Windows Powershell need help with Regular Expressions (RegEx) pattern

I am working with automating some tasks and am having issues with using regular expressions.  Here is part of some powershell lines that I am working on:

$InputFile = 'C:\Batch\Log\Quota.log'
$OutputFile = 'C:\Temp\Userlist.csv'
$RegEx = "This is where I am having difficulty"
Select-String -Path $InputFile -Pattern $RegEx -AllMatches | % {$_.Matches} | % {$_.Value} > $OutputFile

I have output in a file, "quota.log" which contain 'errors'.  Example are shown below

=========================================================================
The operation couldn't be performed because object 'hsuryawans' couldn't be found on 'DC1.University.edu'.
    + CategoryInfo          : NotSpecified: (0:Int32) [Set-Mailbox], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : 3CF4B73F,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
 
The operation couldn't be performed because object 'voleti' couldn't be found on 'DC1.University.edu'.
    + CategoryInfo          : NotSpecified: (0:Int32) [Set-Mailbox], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : D35847FD,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
 
The operation couldn't be performed because object 'egrinman' couldn't be found on 'DC1.University.edu'.
    + CategoryInfo          : NotSpecified: (0:Int32) [Set-Mailbox], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : 21A1FB11,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
=========================================================================
If I set the $RegEx value to “DC1.University.edu” I get back three returns so I know the Select-String command line works fine.

What I wish to get back is just the unique values for each ‘error’:

'hsuryawans'
'voleti'
'egrinman'

I have tried some tests setting the value of $RegEx but can’t seem to get what I wish.  This file contains multiple unique values contained within a single quote with no spaces and only has alphabetic character (no numbers, spaces or special characters like “.”’s)

As a bonus if someone know how to put a "header" on the output .csv file called Name; this would be appreciated.
winsystemsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SubsunCommented:
Try this and see if it works for you...
GC C:\Temp\quota.log | 
	Select-string -Pattern "\s'([^']+)'\s" | 
		select  -ExpandProperty Matches | 
 % { $_ | Select @{N="Name";E={$_.groups[1].value}}}|
Export-Csv C:\Temp\Error.csv -NTI

Open in new window

BTB, It would be more easy if you do the error control on the script which generate "quota.log".
0
footechCommented:
You could try
$RegEx = "'(\w+)'" 
Select-String -Path $InputFile -Pattern $RegEx -AllMatches | % {$_.Matches} | % {$_.groups[1].value}

Open in new window


Since you're not really outputting a .CSV, you can just add the header to beginning of the file like below, sometime before adding the rest of the content.
Set-Content $OutputFile -value "Name"

Open in new window

Another way is to incorporate everthing into one command
Select-String -Path $InputFile -Pattern $RegEx -AllMatches | % {$_.Matches} | % {$_.groups[1]} | Select @{n="Name";e={$_.Value}} | Out-File $OutputFile

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
winsystemsAuthor Commented:
Thank you both for your different perspectives on good solutions
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.