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?
question from:
https://stackoverflow.com/questions/65906608/explain-powershell-void-behavior 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…