P S
asked on
Powershell script to find name of group which server is part of
There are close to 15 security groups which start with "XY_*". I have couple of windows server in a CSV file and each server is member of 1 group out of those 15 groups. I need to find which server is member of which group and it's name.
can someone help me with a powershell script?
Thanks
PS
can someone help me with a powershell script?
Thanks
PS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
^CN= - match "CN=" at the beginning of the string (^)
(?<Group> - open a named group 'Group'
$($prefix).*? - match anything .* non-greedy (shortest match possible), starting with the prefix selected ...
) - [close the named group - $Matches['Group'] will contain the actual group name extracted from the DN]
,(CN|DC|OU)=" - ... until a comma followed by either CN, or DC, or OU, and an = sign.
There are hundreds of websites explaining regular expressions; they're not limited to PowerShell. There may be slight differences for the more complex constructs, but the basics apply to most of the languages that have RegEx support (just don't use findstr.exe - its RegEx support is just horrible ...)
Regular Expression Language - Quick Reference
https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference
(?<Group> - open a named group 'Group'
$($prefix).*? - match anything .* non-greedy (shortest match possible), starting with the prefix selected ...
) - [close the named group - $Matches['Group'] will contain the actual group name extracted from the DN]
,(CN|DC|OU)=" - ... until a comma followed by either CN, or DC, or OU, and an = sign.
There are hundreds of websites explaining regular expressions; they're not limited to PowerShell. There may be slight differences for the more complex constructs, but the basics apply to most of the languages that have RegEx support (just don't use findstr.exe - its RegEx support is just horrible ...)
Regular Expression Language - Quick Reference
https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference
ASKER
Thanks obDA. you're the best.
ASKER
ObDA gave a perfect script. please close this question
ASKER
Thanks again