Hey Guys,
I'm writing a script to list the properties of SharePoint groups.
This piece of code works fine but returns all Sharepoint groups in $site, meaning hundreds of records.
$site = Get-SPSite https://MyWeb/MySiteCollection
$groups = $site.RootWeb.sitegroups
foreach ($grp in $groups) { do something }
So I was looking to filter the list of groups; and I came up with this other piece of code, which also works.
$site = Get-SPSite https://MyWeb/MySiteCollection
$groups = $site.RootWeb.sitegroups | ? {$_.Name -like "Training*"}
foreach ($grp in $groups) { do something }
Then I thought, why not storing the names of the groups I'm interesting in an array and select from $groups only the ones where the group name matches one of the names in my array.
So I created a file named 'Groups.ini' and typed the names of the groups I'm interested in. I wrote this script, but it doesn't work
$site = Get-SPSite https://MyWeb/MySiteCollection $mygroups = Get-Content D:\Tools\Groups.ini $groups = $site.RootWeb.sitegroups | ? {$_.Name -like $mygroups} foreach ($grp in $groups) { do something }
The line I'm interested in is
$groups = $site.RootWeb.sitegroups | ? {$_.Name -like $mygroups}
How can I select the items from $groups where the name is one of the value of my array $mygroups ?
Thanks in advance and have a nice day