My script exports some information from Sharepoint sites to a .CSV
file.
# Enter Web Application URL
$WebAppURL="http://server"
# Enter Path to CSV-file
$CSVFilePath="Path"
$SiteCollections = Get-SPWebApplication $WebAppURL | Get-SPSite -Limit All
$Tree = foreach ($Site in $SiteCollections) {
foreach ($Web in $Site.AllWebs) {
$Groups = New-Object System.Collections.ArrayList
foreach ($Group in $web.Groups) {
[void]$Groups.Add($Group.Name)
}
$Groups = $Groups -join ','
[PSCustomObject]@{
Url = $web.URL
Title = $web.Title
CountOfLists= $web.Lists.Count
PermissionsInherited = $web.Permissions.Inherited
Groups = $Groups
}
}
}
$Tree | Export-CSV $CSVFilePath -NoTypeInformation -Encoding UTF8
If I use [void]
before $Groups.Add($Group.Name)
it works correctly, but without [void]
, the script returns an empty .CSV
file.
Why does this happen?