I am having a problem with a script that I can’t figure out with accessing values out of a MatchInfo Type. I will give a bit of background as i am new to PS so it may be that my workflow is not ideal.
- Get a list of users from AD with specified values
- Check a csv file to see if that user exists in the file
- If the user is in the csv, get the values.
- Compare the values between the AD object and the file
Where I have a problem is getting the values from csv after the search
This is what I am doing
Get the csv
$FromFile = Import-Csv $MyFile
Check the file contains the user
$SearchUser = $FromFile | Select-String -pattern $CN -casesensitive
I am then unable to retrieve any returned values, by doing something like
When I output the $SearchUser it looks like an array
But because the type has changed to MatchInfo I don’t know how to retrieve the values.
I have tried the below to try and make an array but to no avail.
$var = @() $var += $FromFile | Select-String -pattern $CN -casesensitive $var.cn
$var =@($FromFile | Select-String -pattern $CN -casesensitive) $var.cn
[ARRAY]$var = $FromFile | Select-String -pattern $CN -casesensitive $var.cn
Any help in returning the values or using an alternative to Select-String would be great.